jQuery – Click Through Div / Element to Underlying Element

Although I would much rather tell you to rewrite your code to get this working properly, there are ways around it. If you’ve ever finished writing your markup and ended up with an overlaying div or other element and noticed that your links/click events are no longer working, there is an elegant solution that is cross-browser compatible! Using jQuery, we are going to hide the element in question, send a click() trigger, and then show that element again. <!–more–>

    var l = $(window).scrollLeft();
    var t = $(window).scrollTop();

    //here we hide our element in question
    //cause click even to underlying element.
    $(document.elementFromPoint(e.pageX-left, e.pageY-top)).click();

Some CSS to go along with it, keeping the Pointer.

.your-element { cursor:pointer; position:absolute; width:100%; display:block; }
.your-element .sub-element { display:block; width:auto; }
Posted in CSS, jQuery
  • Nicolas_Cacace

    var l = $(window).scrollLeft();
    var t = $(window).scrollTop();

    Is this relevant?