Element Methods: getBoundingClientRect()

By: Dusty Arlia
Published on Sunday, September 14, 2014 at 1:02 PM
Last Updated on Friday, July 10, 2015 at 12:12 AM
Total Updates: 2

The getBoundingClientRect() method of the Element JavaScript object is used to get the position of an element. It gets called on an Element object and takes no arguments. It returns an object with the left, right, top, and bottom (and usually width and height) properties which hold the Element object's viewport coordinates. The top, left properties hold the element's position from its top-left corner, while the bottom, right properties hold its position from the bottom-right corner.

The coordinates returned by this method include the border and padding of the element, but not its margins.