Dustin Jackson Dustin Jackson - 4 months ago 41
Javascript Question

Javascript/jquery, get all divs location at (x,y). Forwarding touches?

Possible Duplicate:

How to get a list of all elements that resides at the clicked point?

I know I can get the element with the highest z-index by using

The problem is I need to get every div that contains the touch event's location.

How can I propagate touches to elements underneath?

I have seen some hacky solutions that show/hide elements while re-generating the event, or pointer-events style with css, however I cannot use these and they may cause flickering...

The following diagram illustrates what I need to do:

If the purple, green, and blue boxes represent the div elements, and the red dot is the touch location, I need a function that would return "div3, div2, div1".


No flickering with this code:

    var x = e.pageX, y = e.pageY;
    var res = [];

    var ele = document.elementFromPoint(x,y);
    while(ele && ele.tagName != "BODY" && ele.tagName != "HTML"){
        ele.style.display = "none";
        ele = document.elementFromPoint(x,y);

    for(var i = 0; i < res.length; i++){
        res[i].style.display = "";