Skip to main content Accessibility Feedback

Selectors

document.querySelectorAll()

Find all matching elements on a page. You can use any valid CSS selector.

// Get all button elements
let buttons = document.querySelectorAll('button');

// Get all elements with the .bg-red class
let elemsRed = document.querySelectorAll('.bg-red');

// Get all elements with the [data-snack] attribute
let elemsSnacks = document.querySelectorAll('[data-snack]');

Preorder my new course on Web Components! Want to learn how to build Web Components from scratch, master best practices, and more? Preorder today and get $100 off of the launch price.


Find this useful? You can support my work by purchasing an annual membership.