Vladimir Kishlaly
Vladimir Kishlaly

Reputation: 1942

JQuery and z-index

I have two DIVs:

<div id="div1"></div>
<div id="div2"></div>

In special cases div2 takes z-index:999. And in that case I can't to catch click on div1. Defined jquery funciton:

$j = jQuery.noConflict();
$j(function() {
    $j(document).click( function(e) {
        var clicked = $j(e.target);
    })
})

So, scenarion is follows:

Are there any ways to handle all clicks made on the whole screen?

Upvotes: 0

Views: 173

Answers (1)

Frederik.L
Frederik.L

Reputation: 5620

if you want to make sure to handle every clicks over any divs of any depth, you can validate that the mouse is over while clicking in the document then trigger the click event of that div. What about :

$(document).click(function(e){
    $('div').each(function(){
        if (e.pageX >= $(this).position.left &&
            e.pageX <= $(this).position.left+$(this).width() &&
            e.pageY >= $(this).position.top &&
            e.pageY <= $(this).position.top+$(this).height()
         ){
            $(this).trigger('click');
         }
    });
});

This is an overkill solution but it may work.. hope this help.

Upvotes: 1

Related Questions