<div class="parent">
<div class="child">
</div>
</div>
<script type="text/javascript">
$(document).on("click", ".parent", function(event){
doAjaxCall();
});
$(document).on("click", ".child", function(event){
doSomething(); // and DON'T call doAjaxCall();
});
</script>
event.stopPropagation(); and return false; is also not working. What could be the problem?
Edit: okay, obvious it is working on js fiddle: http://jsfiddle.net/Smbb4/
I got to check my code once again..
Edit2: Solution:
$('.parent').click(function(event) {
if ( $(event.target).closest('.child').length > 0 ) {
var close = $(event.target).closest('.child');
var windowID = close.data('windowid');
closeWindow(windowID);
return false;
}
});
You only need one click handler, for the parent. Handle the event the regular way, unless the original target was within the child, in which case you branch and do something different.