Selector Engines: Right to Left
I was recently looking at popular development site and found the following snippet:
This snippet found the desired elements in 1ms according to FireBug's console. A millisecond is lightning fast, but if you slightly change the selector code, you get a faster result:
jQuery("li:nth-child(4)", "#subscribe-main"); // Could use this as well // jQuery("#subscribe-main").find("li:nth-child(4)")....
The selection code above returns the same elements in 0ms. A millisecond difference is negligible in one instance, but in a large application, these milliseconds will add up!
console.time("someKey"); jQuery("#mySelector .more .stuff")... console.timeEnd("someKey");
The console doesn't do better than millisecond precision, but a different result at that precision gets you started in selector enhancement. Happy selector revising!