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

You are here

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'));