Documentation

Student-friendly HTML, CSS, and JavaScript reference with examples

Sections

querySelector

Finds the first element that matches a CSS selector.

const button = document.querySelector('button');
const box = document.querySelector('.box');
const header = document.querySelector('#header');

Returns the element if found, or null if no match exists.