What is DOM Event delegation

0 votes
Can anyone please explain event delegation in JavaScript and how is it useful?
Nov 16, 2022 in Java by Nicholas
• 7,760 points
529 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

DOM event delegation is a way for responding to ui-events via a single common parent rather than each child, using the magic of event "bubbling" (aka event propagation).

When an event is triggered on an element, the following happens:

The event is dispatched to its EventTarget, and any event listeners discovered there are activated. Bubbling events will then activate any further event listeners discovered by following the EventTarget's parent chain upstream, looking for any event listeners registered on each succeeding EventTarget. This upward propagation will continue until the Document.

In browsers, event bubbling serves as the foundation for event delegation. You may now connect an event handler to a single parent element, and it will be run anytime an event happens on any of its child nodes (and any of their children in turn). This is called event delegation. Here's an example of how it works in practice:

<ul onclick="alert(event.type + '!')">
    <li>One</li>
    <li>Two</li>
    <li>Three</li>
</ul>

With that example if you were to click on any of the child <li> nodes, you would see an alert of "click!", even though there is no click handler bound to the <li> you clicked on. If we bound onclick="..." to each <li> you would get the same effect.

answered Nov 17, 2022 by Damonlang
• 700 points

edited Mar 5

Related Questions In Java

0 votes
0 answers

What is event bubbling and capturing?

What is the distinction between event bubbling ...READ MORE

Sep 28, 2022 in Java by Nicholas
• 7,760 points
479 views
+1 vote
3 answers

What is the syntax to declare and initialize an array in java?

You can use this method: String[] strs = ...READ MORE

answered Jul 25, 2018 in Java by samarth295
• 2,220 points
3,800 views
0 votes
2 answers

What is the syntax to initialize an array?

Rather than learning un-Official websites learn from ...READ MORE

answered Aug 2, 2018 in Java by samarth295
• 2,220 points
1,284 views
0 votes
2 answers

What is the difference between implements and extends?

Extends : This is used to get attributes ...READ MORE

answered Aug 3, 2018 in Java by samarth295
• 2,220 points
16,842 views
0 votes
1 answer

What is the difference between jdk and jre?

JRE: It stands for Java Runtime Environment. ...READ MORE

answered Apr 20, 2018 in Java by Akrati
• 3,190 points
2,287 views
0 votes
2 answers

What is the use of toString method in Java and how can I use it ?

Whenever you require to explore the constructor ...READ MORE

answered Aug 23, 2018 in Java by Daisy
• 8,140 points
4,322 views
0 votes
1 answer

window.onload vs document.onload

For the window.onload by default, it fires ...READ MORE

answered Feb 9, 2022 in Java by Rahul
• 9,680 points
686 views
0 votes
0 answers

event.preventDefault() vs. return false

When I want to prevent other event ...READ MORE

Jun 10, 2022 in JQuery by gaurav
• 23,260 points
1,025 views
0 votes
0 answers

window.onload vs document.onload

Which is more popular: window.onload or document.onload? READ MORE

Sep 28, 2022 in Java by Nicholas
• 7,760 points
648 views
0 votes
0 answers

jQuery.click() vs onClick

I have a huge jQuery application, and ...READ MORE

Feb 8, 2022 in Java by Rahul
• 9,680 points
752 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP