Lesson 18 of 27

Selecting elements

Selecting elements (the DOM)

The DOM is the browser's live model of your page. document.querySelector finds an element with a CSS selector so your code can work with it.

See it run:

Try it Yourself
Loading editor…
Result

Key points

  • The DOM is the live page structure.
  • querySelector('.class') finds the first match.
  • getElementById('id') is a quick id lookup.

Your turn: select the element by a different selector.

Q&A · 0

Enrol to ask questions and join the discussion.

No questions yet — be the first to ask.