Skip to content
Create a gist now

Instantly share code, notes, and snippets.

Embed URL


Subversion checkout URL

You can clone with
Download ZIP
Returns all elements under the position [clientX,clientY] in an array
* Returns all elements under the position [clientX,clientY] in an array
* @param int X position relative to the viewport
* @param int Y position relative to the viewport
* @param domElm The root element at which to stop looping. Defaults to document.body
* @returns array List of elements under the given position
document.elementsFromPoint = function(clientX,clientY,root) {
// root defaults to document.body
if (root == undefined)
root = document.body;
var elements = [];
var elm;
while (elm = document.elementFromPoint(clientX,clientY)) {
if (elm == root)
// store the original display style and hide the current layer by setting display to none
elm.oldDisplay =; = 'none';
// restore the original display values
for (var i = 0; i < elements.length; i++) {
elements[i].style.display = elements[i].oldDisplay;
delete elements[i].oldDisplay;
return elements;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.