msElementsFromRect method
Returns an node list of elements that are under a rectangle defined by left, top, width, and height.
![]() |
*object.*msElementsFromRect(left, top, width, height, retVal)
left [in]
Type: Floating-pointtop [in]
Type: Floating-pointwidth [in]
Type: Floating-pointheight [in]
Type: Floating-pointretVal [out, retval]
Type: NodeList
The following code sample creates a series of overlapping <div> blocks of varying colors. When you click, it uses msElementsFromRec() to get all the elements that are under a 50 pixel rectangular area and changes the background color to gray. Because all elements are returned, including <body> and <html> we only change the background color on the elements with a nodeName of DIV.
var hitTargets = document.msElementsFromRect(e.clientX - 25, e.clientY - 25, 50, 50); // captures elements within 50px block