views:

168

answers:

4

Is possible with javascript/jquery to get the top position of an element?

The element is a table, if that matter.

A: 

Try: $('#mytable').attr('offsetTop')

toby
this works, is corss-browser? I can't test in all browsers, only in firefox and IE6+
eKek0
everything in jQuery is *supposed* to work in the browsers specified on the home page for jQuery.
geowa4
A: 

document.getElementById("elem").style.top is how you reach this in JS.

Pradeep
That will only work if the style was set with Javascript
Josh Stodola
+3  A: 
$("#myTable").offset().top;

This will give you the computed offset (relative to document) of any object.

xandy
+3  A: 

If you want the position relative to the document then:

$("#myTable").offset().top;

but often you will want the position relative to the closest positioned parent:

$("#myTable").position().top;
Prestaul
This solved my problem too, thanks a lot
Waleed Eissa