I have some elements positioned via CSS this way:
#myItem{
position: absolute;
left: 50%;
margin-left: -350px;
}
I'd like to get their distance from top and left margin of the page. How can I get those measure with javascript/jquery?
Thanks
I have some elements positioned via CSS this way:
#myItem{
position: absolute;
left: 50%;
margin-left: -350px;
}
I'd like to get their distance from top and left margin of the page. How can I get those measure with javascript/jquery?
Thanks
Share Improve this question asked Sep 27, 2010 at 17:38 ArtoAleArtoAle 2,9772 gold badges27 silver badges50 bronze badges2 Answers
Reset to default 6Take a look at jQuery's
.position()
and
.offset()
EDIT: As mentioned by @Nick, .offset() is what you want if you need the position relative to the document
$("#myItem").offset().top;
You can use .offset()
for this:
var offset = $("#myItem").offset();
//use offset.left, offset.top
You can give it a try here.