[javascript] How to get the top position of an element?

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

The element is a table, if that matters.

This question is related to javascript jquery

The answer is


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

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


var top = event.target.offsetTop + 'px';

Parent element top position like we are adding elemnt inside div

var rect = event.target.offsetParent;
         rect.offsetTop;

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