Repaso
EspaƱol

What does document.querySelector(".btn") return?

Options

  1. All of the elements that have the class btn
  2. The first match of .btn, or null if none (Correct option)
  3. The one element whose id is btn in the page
  4. A string with the HTML of that one element

Answer

The first element matching the CSS selector .btn, or null if none

Why

querySelector accepts any CSS selector and returns the FIRST matching element, or null if nothing matches.

querySelectorAll returns ALL matches as a list.

.btn means class 'btn'; #btn would mean id 'btn'.

Remember

querySelector = first match. querySelectorAll = all matches.

Key terms

Practice this question in Repaso