Skip to content

Commit 9fb45df

Browse files
committed
[jQuery] better performance for DOM queries. fixes airbnb#22
1 parent 2dadef9 commit 9fb45df

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,20 +1178,27 @@
11781178
}
11791179
```
11801180

1181-
- Scope jQuery object queries with find. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/13)
1181+
- For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > .ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)
1182+
- Use `find` with scoped jQuery object queries.
11821183

11831184
```javascript
11841185
// bad
1185-
$('.sidebar ul').hide();
1186+
$('.sidebar', 'ul').hide();
11861187
11871188
// bad
1189+
$('.sidebar').find('ul').hide();
1190+
1191+
// good
1192+
$('.sidebar ul').hide();
1193+
1194+
// good
11881195
$('.sidebar > ul').hide();
11891196
1190-
// bad
1191-
$('.sidebar', 'ul').hide();
1197+
// good
1198+
$sidebar.find('ul');
11921199
11931200
// good
1194-
$('.sidebar').find('ul').hide();
1201+
$($sidebar[0]).find('ul');
11951202
```
11961203

11971204
**[[⬆]](#TOC)**

0 commit comments

Comments
 (0)