Skip to main content

Jquery find the top, bottom, left, right of an element on the page using the offset

Member for

2 years 2 months
Submitted by admin on

This function below allows the developer to function find the top, bottom, left, right of an element on the page using the offset.

var elementPosition = function(idClass) {
  var element = $(idClass);
  var offset = element.offset();

  return {
     'top': offset.top,
     'right': offset.left  element.outerWidth(),
     'bottom': offset.top  element.outerHeight(),
     left': offset.left,
  };
};

console.log(elementPosition('#my-class-or-id'));