Find elements on the page
querySelector returns the first match, querySelectorAll returns all of them.
JavaScript · Find elements on the pageBeginner
const title = document.querySelector('h1');
const byId = document.getElementById('menu');
const links = document.querySelectorAll('nav a'); // NodeList
links.forEach(a => console.log(a.href));
const list = [...links].map(a => a.textContent.trim()); // turn into a real array
const firstInside = byId?.querySelector('.active');domquerySelectorgetElementById