How do I get the position or offset of an element on the page

To get the position or offset of an element on the page, you can use JavaScript. The following example demonstrates how to achieve that using the `getBoundingClientRect` method.

<script> function getElementPosition(element) { var rect = element.getBoundingClientRect(); return { top: rect.top + window.scrollY, left: rect.left + window.scrollX }; } // Usage example: var myElement = document.getElementById('myElement'); var position = getElementPosition(myElement); console.log('Element Position:', position); </script>

JavaScript getBoundingClientRect element position DOM manipulation