Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>As @JonnySooter posted above in the comments, if your browser requirements don't include IE &lt;= 10 (see: <a href="http://caniuse.com/pointer-events" rel="nofollow noreferrer">caniuse pointer-events</a>) you can use the style: <code>pointer-events: none;</code> and mouse events will be ignored on <code>tail</code>.</p> <p>Otherwise, you could determine which elements are under the mouse position at the time of the click event.</p> <p>Using the answer from this question: <a href="https://stackoverflow.com/questions/5598953/find-elements-that-are-stacked-under-visually-an-element-in-jquery">find elements that are stacked under (visually) an element in jquery</a>, you can determine which element should be clicked:</p> <p><kbd><a href="http://jsfiddle.net/davidcl64/hj57k/1907/" rel="nofollow noreferrer">Demo Fiddle</a></kbd></p> <p>HTML: (Modified to be sequence of DIV's)</p> <pre><code>&lt;div&gt;kjashkfjaiufaewhfejakdkskjashkfjaiufaiufaewhfejakdkskjashkfjaiufaewhf&lt;/div&gt; &lt;div&gt;kjashkfjaiufaewhfejakdkskjashkfjaiufaiufaewhfejakdkskjashkfjaiufaewhf&lt;/div&gt; … &lt;div id="tail"&gt;&lt;/div&gt; </code></pre> <p>Code (works with jQuery 1.4.2 as in the OP's fiddle):</p> <pre><code>function GetAllElementsAt(x, y) { var $elements = $("body *").map(function() { var $this = $(this); var offset = $this.offset(); var l = offset.left; var t = offset.top; var h = $this.height(); var w = $this.width(); var maxx = l + w; var maxy = t + h; return (y &lt;= maxy &amp;&amp; y &gt;= t) &amp;&amp; (x &lt;= maxx &amp;&amp; x &gt;= l) ? $this : null; }); return $elements; } // Change to '.on' in more recent version of jQuery $('#tail').bind('click', function(evt) { var $elements = GetAllElementsAt(evt.pageX, evt.pageY); // In this example, "There can be only one" - the zero'th element will be // the clicked element alert("You clicked on div #" + ($($elements[0]).prevAll().length + 1)); }); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload