Skip to content

Commit 61a57ce

Browse files
committed
Event Extensions: Cleanup
1 parent 20462df commit 61a57ce

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

page/events/event-extensions.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: jQuery Event Extensions
33
level: advanced
44
---
5+
56
jQuery offers several ways to extend its event system to provide custom functionality when events are attached to elements. Internally in jQuery, these extensions are primarily used to ensure that standard events such as `submit` and `change` behave consistently across browsers. However, they can also be used to define new events with custom behavior.
67

78
This document covers the extensions available starting with jQuery 1.7; a sparsely documented subset of this functionality has been available since jQuery 1.3 but the differences in functionality are extensive. For an overview of special events in earlier versions, see [Ben Alman's jQuery Special Events](http://benalman.com/news/2010/03/jquery-special-events/) article.
@@ -10,7 +11,7 @@ This document covers the extensions available starting with jQuery 1.7; a sparse
1011

1112
### Events overview and general advice
1213

13-
When writing an event extension, it is essential to understand the flow of events through jQuery's internal event system. For a description of the event system from the API level, including a discussion of event delegation, see the [`.on()`](http://api.jquery.com/on) method.
14+
When writing an event extension, it is essential to understand the flow of events through jQuery's internal event system. For a description of the event system from the API level, including a discussion of event delegation, see the [`.on()`](http://api.jquery.com/on/) method.
1415

1516
To simplify event management, jQuery only attaches a single event handler per element per event type (using `addEventListener` on W3C-compliant browsers or `attachEvent` on older IE) and then dispatches to event handlers that are attached via jQuery's APIs. For example, if three "click" event handlers are attached to an element, jQuery attaches its own handler when the first handler is attached and adds the user's event handler to a list to be executed when the event occurs. For subsequent event handlers, jQuery only adds them to its own internal list since it has already called the browser to attach its solitary handler. Conversely, jQuery removes its own event handler from the browser when the final event of a particular type is removed from the element.
1617

@@ -122,11 +123,11 @@ elem.on( "pushy", function( event ) {
122123
$( "body" ).append( "I am pushy but still a " + event.type + "!" );
123124
});
124125
125-
elem.trigger( "click" ); // triggers both handlers
126+
elem.trigger( "click" ); // Triggers both handlers
126127
127128
elem.off( "click" );
128129
129-
elem.trigger( "click" ); // still triggers "pushy"
130+
elem.trigger( "click" ); // Still triggers "pushy"
130131
131132
elem.off( "pushy" );
132133
```

0 commit comments

Comments
 (0)