Reguarding jQuery, I’ve read somewhere that slecting by class can be significantly slower than selecting by ID.
When using the :first selector, does jQuery find all instances and only return the first element? Or does the parser stop once the first element is found?
I know this isn’t a direct answer to your question but:
Using
.first()is about ten times faster than using:first. Tested using FirefoxAs the comments have suggested, try using JsPerf