Sometimes, we want to stop event propagation with inline onclick attribute with JavaScript.
In this article, we’ll look at how to stop event propagation with inline onclick attribute with JavaScript.
How to stop event propagation with inline onclick attribute with JavaScript?
To stop event propagation with inline onclick attribute with JavaScript, we call stopPropagation
.
For instance, we write
<span
onclick="event.stopPropagation(); alert('you clicked inside the header');"
>
something inside the header
</span>
to call event.stopPropagation
when we click on the span to stop the propagation of the click event.
And then we call alert
to show some text.
Conclusion
To stop event propagation with inline onclick attribute with JavaScript, we call stopPropagation
.