How To Stop Event Propagation On Onclick Event In Html Attribute?
I have a html element with an onclick attribute and I need to prevent that event from bubbling up. I tried doing this:
and this: <
Solution 1:
Use event.stopPropagation method of Event
. There is a mistake in your second code snippet where you do not pass event
to the anonymous function. Fixed code:
<div onclick="(function(e) { e.preventDefault(); e.stopPropagation(); })(event)">
Post a Comment for "How To Stop Event Propagation On Onclick Event In Html Attribute?"