If I have a parent div that is positioned absolutely and then a child div that has a higher z-index and is positioned relatively, is there a way to have a click event register only if the parent div is clicked, but not the inside div?
Relevant jsFiddle
Updated fiddle with text input example
click(function(e) { e. stopPropagation(); }); As said by jQuery Docs: stopPropagation method prevents the event from bubbling up the DOM tree, preventing any parent handlers from being notified of the event.
$(".parent").click(function(e) {
if (e.target == this) {
$(this).hide();
}
});
DEMO: http://jsfiddle.net/Bt5HA/4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With