Skip to content

Commit a1d65c8

Browse files
keatingscottgonzalez
authored andcommitted
Event Delegation: Delegation affects all descendants not just children
Closes jquerygh-496
1 parent dae6294 commit a1d65c8

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

page/events/event-delegation.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ attribution:
88

99
## Introduction
1010

11-
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all children matching a selector, whether those children exist now or are added in the future.
11+
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all descendants matching a selector, whether those descendants exist now or are added in the future.
1212

1313
## Example
1414

@@ -71,7 +71,7 @@ $( "#list" ).on( "click", "a", function( event ) {
7171
});
7272
```
7373

74-
Notice how we have moved the `a` part from the selector to the second parameter position of the `.on()` method. This second, selector parameter tells the handler to listen for the specified event, and when it hears it, check to see if the triggering element for that event matches the second parameter. In this case, the triggering event is our anchor tag, which matches that parameter. Since it matches, our anonymous function will execute. We have now attached a single *click* event listener to our `<ul>` that will listen for clicks on its children anchors, instead of attaching an unknown number of directly bound events to the existing anchor tags only.
74+
Notice how we have moved the `a` part from the selector to the second parameter position of the `.on()` method. This second, selector parameter tells the handler to listen for the specified event, and when it hears it, check to see if the triggering element for that event matches the second parameter. In this case, the triggering event is our anchor tag, which matches that parameter. Since it matches, our anonymous function will execute. We have now attached a single *click* event listener to our `<ul>` that will listen for clicks on its descendant anchors, instead of attaching an unknown number of directly bound events to the existing anchor tags only.
7575

7676
### Using the Triggering Element
7777

0 commit comments

Comments
 (0)