Skip to content

Commit

Permalink
Use 'event delegation' with list of elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanyan committed Jul 11, 2013
1 parent 8444cb1 commit 6f5578f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion README.md
Expand Up @@ -639,7 +639,29 @@ $.retryAjax({
// good (faster)
$($sidebar[0]).find('ul');
```
- Use 'event delegation' with list of elements.
```html
<ul>
<li>list1</li>
<li>list1</li>
<li>list1</li>
<li>list1</li>
<li>list1</li>
</ul>
```
```js
// bad
$("ul li").on("click", function() {
$(this).text("aha");
});

// good
$("ul").on("click", "li", function() {
$(this).text("aha");
});
```
# Ref
* jQuery Core Style Guide - http://docs.jquery.com/JQuery_Core_Style_Guidelines
* Airbnb JavaScript Style Guide - https://github.com/airbnb/javascript
Expand Down

0 comments on commit 6f5578f

Please sign in to comment.