DEV Community

Passionate Coder
Passionate Coder

Posted on

4 2

Interview questions related to event bubbling in Javascript?

1) What is Event bubbling in Javascript. Give Example

Event bubbling is the method of event propogation in which event travels from innermost element to the outermost parent element.

Like if we have below structure

<section onclick="alert('section')">
   <div onclick="alert('div')">
     <p onclick="alert('paragraph')"> 
        This is paragraph
     </p>
   </div>
</section>
Enter fullscreen mode Exit fullscreen mode

If click event of paragraph invoked it will call click handlers of all in below order

p>div>section

Event bubbling is also known as Event Propagation or Event Delegation

2) How can event bubbling can be stopped?

stopPropagation() method of javascript used for stopping event bubbling

For more such videos you can check my channel

Top comments (0)

Image of Stellar post

Check out Episode 1: How a Hackathon Project Became a Web3 Startup πŸš€

Ever wondered what it takes to build a web3 startup from scratch? In the Stellar Dev Diaries series, we follow the journey of a team of developers building on the Stellar Network as they go from hackathon win to getting funded and launching on mainnet.

Read more

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay