Trying to wrap my head around the jQuery “.not()” function, and running into a problem. I would like to have the parent div to be “clickable” but if a user clicks on a child element, the script is not called.
$(this).not(children()).click(function(){
$(".example").fadeOut("fast");
});
the html:
<div class="example">
<div>
<p>This content is not affected by clicks.</p>
</div>
</div>
To do this, stop the click on the child using .stopPropagation:
This will stop the child clicks from bubbling up past their level so the parent won’t receive the click.
.not()is used a bit differently, it filters elements out of your selector, for example:For clicking, your problem is that the click on a child bubbles up to the parent, not that you’ve inadvertently attached a click handler to the child.