Selector speed - class only vs tag with class
I'm trying to figure out which selector is faster (assuming that the class 'foo' only appears on input tags)...
- $('.foo');
- or
- $('input.foo');
From what I've seen online, it seems that people recommend $('input.foo'), but in some limited testing it appears that $('.foo') is much faster in both FF and Chrome. In IE, both methods seem to produce similar results. Here is a fiddle with a simple example...
http://jsfiddle.net/962sN/1/
Have browsers started implementing native ways to find all elements with a given class name? Would that explain why $('.foo') seems to be faster? What should the preferred approach be?