Are jQuery selection rules changed for new browsers?

I just ran this jsPerf test in Chrome 18 and found that it .classperforms much better than tag.classdespite myriad resources that say otherwise . I know this question was recently asked on SO , but without a definitive / satisfactory answer other than "do not use jQuery." Can someone shed light on the latest best practices?

NOTE. Assume that clarity and semantics are taken care of (for example, I have a class on a tethered tag with the name item-linkit will come off just as clearly with the help a.item-linkas it will .item-link).

+3
source share
2 answers

It is better implemented in the latest browsers getElementsByClassName, and therefore, when you use the jquerys class selector, it immediately returns to this method and, consequently, to the difference in performance and gain.

When you are preceded by a tag selector, first jquery should process your selector and then break it into different markers, and then it will start searching for the control, not sure which order is here, regardless of whether all elements with className are fetched first, and then an extra selector is added, or vice versa, but I'm sure you can explore it by looking at the jquery source code ..

, , , , - , , , . ?:/

+1

, , , , script.

+4

All Articles