Selecting Elements
JS · DOM Manipulationsyntax
document.querySelector(selector)
document.querySelectorAll(selector)
document.getElementById(id)example
const header = document.querySelector("h1");
const buttons = document.querySelectorAll(".btn");
const main = document.getElementById("main-content");
// querySelectorAll returns a static NodeList
buttons.forEach(btn => {
console.log(btn.textContent);
});Note querySelector returns the first match or null. querySelectorAll returns a static NodeList (does not auto-update). Use Array.from() if you need full array methods.