getClientRects
The getClientRects() method in JavaScript is used to retrieve a static, read-only list of DOMRect objects. Each DOMRect object represents a rectangle that describes the size and position of a rendered text fragment. This method is particularly useful for measuring the bounding boxes of text elements within the viewport.
When called on an element, getClientRects() returns a NodeList of DOMRect objects. Each DOMRect object has properties
For example, a long paragraph that wraps to several lines will result in getClientRects() returning a separate
The information provided by getClientRects() is a snapshot of the element's position and size at the time