I have an html as below :
<div class="parent">
<a href="#">parent</a>
<div class="child">child</div>
</div>
Here is my Jquery binding an click
event :
$(document).ready(function(){
$('.parent').on('click', function(){
alert('parent div');
});
$('.child').on('click', function(){
alert('child div');
});
});
I want, if I click on ".child"
div, then event bound on "div.parent"
should not be called.
Again if I click on ".parent"
div and its bound event should be executed.
I have tried with following -
$('.child').on('click', function(){
alert('child div');
$(this).parents('.parent').off('click');
return false;
});
But above code has unbound the "click"
event on parent div
permanently,
and again its click event does not trigger.