1.避免包含
s会只用本地的querySelectorAll()
// Slower (the zero-based :even selector is a jQuery extension)$( "#my-table tr:even" ); // Better, though not exactly equivalent$( "#my-table tr:nth-child(odd)" );
2.避免过度特性
$( ".data table.attendees td.gonzalez" ); // Better: Drop the middle if possible.$( ".data td.gonzalez" );
3.尽量使用id选择器
// Fast:$( "#container div.robotarm" ); // Super-fast:$( "#container" ).find( "div.robotarm" );
4.避免通配符选择
$( ".buttons > *" ); // Extremely expensive.$( ".buttons" ).children(); // Much better. $( ":radio" ); // Implied universal selection.$( "*:radio" ); // Same thing, explicit now.$( "input:radio" ); // Much better.