I'm trying to create a function to get the positions of elements, but when I try to get the bottom offset it return not defined, what am I missing?
This is my attempt:
var myDiv = jQuery('.div');
function getOffset(el) {
var off = jQuery(el).offset();
return {
left: off.left,
right: off.left + el.outerWidth(),
top: off.top,
bottom: off.top + el.outerHeight(),
hCenter: (bottom + top) /2,
wCenter: (right + left) /2
};
}
var myDivPosition = getOffset(myDiv);
console.log(
"top = " + myDivPosition.top +
"bottom = " + myDivPosition.bottom +
"hCenter = " + myDivPosition.hCenter +
"left = " + myDivPosition.left +
"right = " + myDivPosition.right +
"wCenter = " + myDivPosition.wCenter
);
I get in the console:
Uncaught ReferenceError: bottom is not defined