JavaScript · Junior · Question 50 of 75
How do you find the first element with the card class on the page?
- ✓Correct answer:
document.querySelector('.card') - 2
document.getElementsByClassName('.card')[1] - 3
document.find('card')
Explanation
querySelector accepts any CSS selector and returns the first element or null. querySelectorAll returns a static NodeList of all matches. getElementsByClassName takes the class name without a dot, and indexing starts at 0.