DEV Community

Discussion on: I Need jQuery

Collapse
 
facundocorradini profile image
Facundo Corradini • Edited

querySelector and getElement are completely different beasts.

querySelectorAll will return a static collection, while getElementsByClassName returns a live collection. This could lead to confusion if you store the results in a variable for later use:

A variable generated with querySelectorAll will contain the elements that fulfilled the selector at the moment the method was called.
A variable generated with getElementsByClassName will contain the elements that fulfilled the selector when it is used (that may be different from the moment the method was called).

Also getElements allow for a single Id or a single class, while query selector can use complex CSS 3 selectors.

And getEllements is a better performer by orders of magnitude

So both tools have their uses

Collapse
 
aurelkurtula profile image
aurel kurtula

Nice!