Trigger event on parent click, but not on child clicks

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 when I click on the parent div, but not inside the div?

Matching jsFiddle

Updated script with sample text input

+7
source share
4 answers
$(".parent").click(function(e) { if (e.target == this) { $(this).hide(); } });​ 

DEMO: http://jsfiddle.net/Bt5HA/4/

+13
source

Change to:

 $('.child a').click(function(e) { $(this).parent('.child').hide(); });​ 
0
source

Access to children and return false when clicking http://jsfiddle.net/Bt5HA/3/

0
source

try it

 $('#child').click(function(event) { event.stopPropagation(); alert('You clicked Child'); }); $('#parent').click(function() { alert('You clicked on Parent'); }); 

You can check the work here http://jsfiddle.net/VnHGh/24/

0
source

All Articles