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:

https://developer.mozilla.org/en-US/docs/Learn/JavaScript/Client-side_web_APIs/Manipulating_documents#Active_learning_Basic_DOM_manipulation

under the Active learning: Basic DOM manipulation heading.

the same thing seems to be said on stackoverflow:

https://stackoverflow.com/questions/26848289/javascript-queryselector-vs-getelementbyid

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

https://caniuse.com/#feat=queryselector

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: