JavaScript JavaScript and the DOM Getting a Handle on the DOM Using CSS Queries to Select Page Elements

Uche Onuekwusi
Uche Onuekwusi
13,741 Points

If i only selecting elements by id, tags and class and do not use document.query selector in developing programs.

If i only select elements by id, tags and class and do not use document.query selector in developing programs. does this make me a bad developer ?

1 Answer

Jennifer Nordell
STAFF
Jennifer Nordell
Treehouse Staff

Hi there, Uche! It absolutely does not make you a bad developer. In fact, using querySelector has a bit of parsing of the DOM going on under the hood which makes it slightly less performant than the others. So if you simply need something to select the id "my-div", it's going to be faster to getElementById('my-div') than the corresponding querySelector. However, you might have a really tricky DOM selection sometimes that requires that you select 3 or 4 things to finally get down to the thing you are after. If that is the case, a querySelector might make your code a bit more concise.

Hope this helps! :sparkles: