Home > UI/UX Development > JavaScript > Event bubbling and capturing in Javascript

Event bubbling and capturing in Javascript

This post was most recently updated on December 28th, 2016

Event bubbling and event capturing are two ways of event propagation in DOM structure.

Ex. There are two HTML elements embedded in one another as:

div_strucuture_bubbbling_capturing

Event bubbling: the event is captured in span element first and then in div.

Event Capturing: the event is captured in div element first and then in span.

Browser Support: In older browsers, some browsers followed bubbling while some in capturing. Although currently all major browsers(IE, FF, Chrome, Safari) support and follow event bubbling.

Enable capturing in Javascript: Javascript currently follow bubbling by default but we can always switch to capturing mode of event propagation. Following is a sample code. View demo here.

Javascript: 

 HTML:

CSS:

This Article is TAGGED in , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">