"Optimize Selectors" guide requires update?
- // Fast:
- $( "#container div.robotarm" );
- // Super-fast:
- $( "#container" ).find( "div.robotarm" );
The
.find()
approach is faster because the first selection is handled without going through the Sizzle selector engine – ID-only selections are handled using
document.getElementById()
, which is extremely fast because it is native to the browser.
$('#nav-sidebar').find('input:checked') vs
$('#nav-sidebar input:checked'):
- Google Chrome 35: about 91% slower
- Internet Explorer 11: about 8% slower
- Firefox 29: about 27% faster
So "
$('#nav-sidebar input:checked')"
is faster to more users and with time the situation will continue to change.
This issue requires testing in different operating systems and browsers with various selectors. Please help testing!