A front-end developer from Mar del Plata, Argentina. Passionate about CSS, accessibility, and JS. Currently working on "just a small fix", as I've been doing for the last 15 years.
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
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
Nice!