DOM Manipulation

document.querySelector

document.querySelector

document.querySelector finds the first element that matches a CSS selector. The selector is a string, so an ID selector includes # and a class selector includes ..

Selecting gives your code a reference to the real element in the page. From there, you can read its text, change it, or attach behaviour later.

Your task: Select the heading with the ID hero-title, store it in heroTitle, then log its textContent. The important part is selecting from the DOM, not typing the heading text yourself.

Tests

  • selects the heading element
  • reads the heading text from the DOM
  • uses querySelector with the heading ID selector
Loading...
Console

Run code to see output.

Previous1 / 80Next