What does document.querySelector(".btn") return?
Options
- All of the elements that have the class btn
- The first match of
.btn, or null if none (Correct option) - The one element whose id is btn in the page
- 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.