When should I use .querySelector() or .getElementByID() to select an ID?

When should I use .querySelector() or .getElementByID() to select an ID?

[https://www.codecademy.com/paths/web-development/tracks/build-interactive-websites/modules/web-dev-interactive-websites/lessons/javascript-dom/exercises/select-element](http://Select and Modify Elements)

MDN seems to indicate that querySelector is the newer preferred method:


under the Active learning: Basic DOM manipulation heading.

the same thing seems to be said on stackoverflow:


the stackoverflow question mentions being less supported by browsers, but the answer is old, if we check caniuse:


we see that the support is now good. So seems querySelector and querySelectorAll are the way to go.

If people still use IE8 or older, they need to re-evaluate their life choices :rofl: