Are there any speed/efficiency differences between the following two lines.
$("table td:not(:first-child)")
and
$("table td").not(":first-child")
I would think that the first would be better since it is removes objects, but is there an actual difference and is it substantial.
Thanks
Depends on the browser.
Browsers that support
querySelectorAll
will get a performance boost with......because it is a valid selector. Older browsers (IE7 and lower) will not.
You need to be careful with the
:not()
selector though. jQuery (Sizzle) extends it with non-standard selectors, so it's easy to breakqSA
.As you can see from the jsperf test,
:not
is on average about twice as fast. Overall though this performance will likely be a very small part of your overall execution time.The jquery docs state:
So really it's up to you to decide if the fractions of a second you gain outweigh the readability.