Skip to content
techsnow

The DOM

Selecting Elements

MethodReturns
document.querySelector(css)The first element matching a CSS selector
document.querySelectorAll(css)All matching elements (a NodeList)
document.getElementById(id)The element with that id
const title = document.querySelector("h1");
const firstCard = document.querySelector(".card");
const allButtons = document.querySelectorAll("button");
const form = document.getElementById("signup");

allButtons.forEach((btn) => console.log(btn.textContent));