Jquery USES the offset of method to get the xy coordinate of the element

  • 2020-03-30 03:53:41
  • OfStack

Get the absolute X and Y coordinates of an element on the page. Offset () method can be used: (body property set margin :0; Padding: 0)


var X = $('#DivID').offset().top; 
var Y = $('#DivID').offset().left; 
 To obtain the relative ( The parent element ) location : 
var X = $('#DivID').position().top; 
var Y = $('#DivID').position().left;


Related articles: