Reputation: 1942
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:
$j(document).click function called if click occurs on any div with the same z-index
$j(document).click function called if click occurs on div with the greater z-index and doesn't called on click on another
Are there any ways to handle all clicks made on the whole screen?
Upvotes: 0
Views: 173
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