Skip to content

Instantly share code, notes, and snippets.

@padolsey
Created January 8, 2010 21:52
Show Gist options
  • Save padolsey/272459 to your computer and use it in GitHub Desktop.
Save padolsey/272459 to your computer and use it in GitHub Desktop.
function getElementsInRegion(x, y, width, height) {
var elements = [],
expando = +new Date,
cx = x,
cy = y,
curEl;
height = y + height;
width = x + width;
while ((cy += 5) < height) {
cx = x;
while (cx < width) {
curEl = document.elementFromPoint(cx, cy);
if ( curEl && !curEl[expando] ) {
curEl[expando] = new Number(0);
elements.push(curEl);
cx += curEl.offsetWidth;
} else {
cx += 5;
}
}
}
return elements;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment