Dom Selectors in javascript

DOM selectors let you find elements in the HTML document. Modern code uses querySelector/querySelectorAll with CSS selectors, but getElementById, getElementsByClassName, and getElementsByTagName also exist. querySelector returns the first match, querySelectorAll returns a static NodeList.

Example

const title = document.getElementById("title");
const buttons = document.querySelectorAll(".btn.primary");

title.textContent = "Updated heading";
buttons.forEach(btn => btn.disabled = true);

This selects a single element by ID and a list of elements by CSS selector, then updates their text and disabled state.