I want to prevent parent click when I clicking on child SPAN. I tried
e.stopPropagation
and thi way
if (!e) e = window.event;
e.cancelBubble = true;
if (e.stopPropagation) e.stopPropagation();
I have html like:
<label for="parent_id"> Some text
<span id="child_id">Click child</span>
</label>
<input id="parent_id" />
Function for Parent element
$('#parent_id').click(function (e) { SomeParentCode }
Function for Child element.
$('#child_id').click(function (e) {
e.stopPropagation();
But I what to prevent parent click
SomeChildCode
}
Use preventDefault and stopPropagation.
$('#child_id').on('click', function (e) {
e.preventDefault();
e.stopPropagation();
});
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