If, hypothetically, the ID of your DOM element happened to be myElement
, you can utilize the following code snippets:
document.getElementById("myElement").offsetLeft; //Returns the left side of the box
document.getElementById("myElement").offsetTop; //Returns the top side of the box
document.getElementById("myElement").offsetLeft + document.getElementById("myElement").offsetWidth; //Calculates the right side of the box
document.getElementById("myElement").offsetTop + document.getElementById("myElement").offsetHeight; //Determines the bottom side of the box
The logic behind determining the bottom and right sides involves adding the width or height of the bounding box to the left or top side respectively.
To streamline the process, consider defining
document.getElementById("myElement")
once and then referencing it in the subsequent lines of code:
var myElement = document.getElementById("myElement");
myElement.offsetLeft; //Obtains the left side of the box
myElement.offsetTop; //Fetches the top side of the box
myElement.offsetLeft + myElement.offsetWidth; //Estimates the right side of the box
myElement.offsetTop + myElement.offsetHeight; //Derives the bottom side of the box