Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to respond to a click outside a certain area?

My document looks like this: enter image description here

Basically the background is one full-screen, transparent div. There are couple problems...if I just create the background div and don't apply any z-index to it, it ends up being on top of everything, and I cannot click on the box. If I set the z-index of the background div to be below the box, I can't seem to click on the background. What I want to do, it to be able to click both on the box, and the background.

var x = document.getElementById("bg");
x.addEventListener("click",reset,false);

function reset() {
   alert("reset was clicked");
}

CLARIFICATION: box is on the same node level as the bg. it is not inside the bg div.

like image 893
antonpug Avatar asked Nov 14 '22 13:11

antonpug


1 Answers

Take a look at this jQuery plugin - even if it doesn't solve your particular question the code could provide insight into your dilemma.

jQuery clickoutside

like image 143
Tuck Avatar answered Nov 16 '22 04:11

Tuck