To stop event propagation with inline onclick attribute with JavaScript, we can call the stopPropagation
method.
For instance, we write
<div onclick="onClick(event);">click me</div>
to set the onclick
attribute to call the onClick
function with the click event
object.
Then we write
function onClick(event) {
event.stopPropagation();
}
to define the onClick
function to call the stopPropagation
method to stop the click event from bubbling up.