I'm using jQuery.
How to deal with it easily?
I'm using jQuery.
How to deal with it easily?
use offset();
var offset = $('#elem1').offset(); $('#elem2').css('top', offset.top );
Try this code:
var offset = $(<dom-element>).offset();
$(<div>).css({ top: (offset.top - $(<div>).height() - 20) + "px",
left: offset.left });
For more information, check out the CSS documentation of jQuery.
Also, for most events you can call event.target
to get the element generating event.
To get current mouse position use event.pageX
and event.pageY
. Note that the event must come from a mouse action: onmousemove
, onmouseup
, onmousedown
, onclick
, etc...