I am wondering which of the following jQuery queries will be faster. I'm looking for matching any span tags that have either the src attribute or the data-src attribute.
var a = $('span[src],span[data-src]');
var b = $('span').filter('[src],[data-src]');
My gut feeling is (b), but there may be optimizations that I don't know about.
Thank.
UPDATE:
Based on a quick test with the elements 100 x span[src]
, 100 x span[data-src]
and 100 x span
: (a) came out 4-8 times faster, depending on the browser. On IE8, it was much faster (about 50 times) and on IE6 / 7 about the same.
What I wonder why is it faster?
(a) jquery querySelectorAll
, . , , .