8
I need you to click off a div
(is a registration screen), the same if close.
What selector should I use so that clicking anywhere outside the div that div closes?
$(????).on("click", function(){
$('div').hide();
});
If there is click on any part or element of div
cannot close because the user will be completing the data.
I would also have to check all the elements within the div. Or I’m wrong?
– Joao Paulo
You will have to detect if the target is the div itself or if you own the div as an ancestor... I will create an example fiddle.
– Miguel Angelo
I believe that
closest
can help you there. Just use the desired div selector as an argument; if it returns more than zero results, it is because the element is inside the div.– mgibsonbr
@mgibsonbr: with
closest
is even more flexible... in my example I usedhas
... but if it had to exclude multiple elements of the event,closest
very helpful.– Miguel Angelo