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
$(".parent").click(function(e) { if (e.target == this) { $(this).hide(); } });
DEMO: http://jsfiddle.net/Bt5HA/4/
Change to:
$('.child a').click(function(e) { $(this).parent('.child').hide(); });
Access to children and return false when clicking http://jsfiddle.net/Bt5HA/3/
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/