Why is getElementsByTagName() faster that querySelectorAll()? - 4 views
-
Thomas Bassetto on 29 Sep 10getElementsByTagName("a") is faster than querySelectorAll("a") in nearly all browsers. There's one very important difference between these two methods, and it's not that one accepts only a tag name and the other accepts a full CSS selector. The big difference is in the return value: the getElementsByTagName() method returns a live NodeList while querySelectorAll() returns a static NodeList. This is extremely important to understand.
-
jpvincent on 29 Sep 10en fait, la création de la liste d'éléments est 90% plus rapide avec getElementsByTagName par contre ça peut être compensé par les accès aux propriétés, plus rapides avec la liste statique retournée par querySelectorAll : http://jsperf.com/access-to-nodes-via-queryselectorall-vs-getelementsbyta/2 donc rien d'absolu, ça dépend de chaque code