You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+5-1
Original file line number
Diff line number
Diff line change
@@ -60,4 +60,8 @@ If the article was pulled in from an outside source you also need to add an attr
60
60
61
61
## How do I get credit for my contribution?
62
62
63
-
We will build the attribution of an article based on the git commit logs. Only use the attribution meta tag to give credit to authors outside of git for an article that was pulled in for instance.
63
+
We will build the attribution of an article based on the git commit logs. Only use the attribution meta tag to give credit to authors outside of git for an article that was pulled in for instance.
64
+
65
+
Writing Style Guide
66
+
67
+
The jQuery Learning Site uses the [same style guide as the jQuery Documentation team](https://github.com/jquery/api.jquery.com#style-guidelines). If you have questions which are not addressed by this style guide, please refer to [idiomatic.js](https://github.com/rwldrn/idiomatic.js/).
Copy file name to clipboardExpand all lines: page/events/history-of-events.md
+9-8
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,8 @@
1
1
---
2
-
title : History of jQuery Events
2
+
title: History of jQuery Events
3
+
level: intermediate
3
4
---
4
-
Throughout the evolution of jQuery the means of event binding has changed for various reasons ranging from performance to semantics. As of jQuery v1.7 the `.on()` method is the accepted means of both directly binding events and creating delegated events. This article aims to explore the history of *event delegation* from jQuery v1.0 - present and how each version leverages it.
5
+
Throughout the evolution of jQuery the means of event binding has changed for various reasons ranging from performance to semantics. As of jQuery v1.7 the `.on()` method is the accepted means of both directly binding events and creating delegated events. This article aims to explore the history of *event delegation* from jQuery v1.0 - present and how each version leverages it.
5
6
6
7
Given the following html, for our example we want to log the text of the each `<li>` to console whenever it is clicked.
7
8
@@ -24,7 +25,7 @@ It is possible to use `.bind()` and attach a handler to every element.
24
25
25
26
```
26
27
$('#list li').bind('click', function(event){
27
-
console.log( $elem.text() );
28
+
console.log( $elem.text() );
28
29
});
29
30
```
30
31
As discussed in the [event delegation](/event/event-delegation) article, this is not optimal.
@@ -42,7 +43,7 @@ Generally we don't associate `.bind()` with *event delegation*, however prior to
42
43
$('#list').bind('click', function(event){
43
44
var $elem = $(event.target);
44
45
if( $elem.is("li") ){
45
-
console.log( $elem.text() );
46
+
console.log( $elem.text() );
46
47
}
47
48
});
48
49
```
@@ -75,7 +76,7 @@ The last element to recieve the *click* event is *document*, this is where our `
Passing the *context* as a second optional argument to the `$()` function has been supported since v1.0. However support for using this *context* with the `$.live()` method was not added until v1.4.
79
+
Passing the *context* as a second optional argument to the `$()` function has been supported since v1.0. However support for using this *context* with the `$.live()` method was not added until v1.4.
79
80
80
81
If we were take our previous `.live()` example and provide it the default *context*, it would look like:
81
82
@@ -100,7 +101,7 @@ In this instance when an `<li>` is clicked the event still bubbles all the way u
The `.delegate()` method provides a clear difference between the *context* of where to attach delegated event handler, and the *selector* to match when the event bubbles up to the delegated element.
104
+
The `.delegate()` method provides a clear difference between the *context* of where to attach delegated event handler, and the *selector* to match when the event bubbles up to the delegated element.
The `on.()` method gives us a semantic approach for creating directly bound events as well as delegated events. It eliminates the need to use the deprecated`.bind()`, `.live()` and `.delegate()` methods, providing a single API for creating events.
116
+
The `on.()` method gives us a semantic approach for creating directly bound events as well as delegated events. It eliminates the need to use the deprecated`.bind()`, `.live()` and `.delegate()` methods, providing a single API for creating events.
All of these ways of *event delegation* were innovative and considered a best practice at the time of their release. Depending on what version of jQuery you have implemented use the appropriate means of *event delegation*.
126
+
All of these ways of *event delegation* were innovative and considered a best practice at the time of their release. Depending on what version of jQuery you have implemented use the appropriate means of *event delegation*.
0 commit comments