- Instant help with your JavaScript coding problems

Select HTML elements by CSS selectors in vanilla JavaScript

Question:
How to select HTML elements by CSS selectors in vanilla JavaScript?
Answer:
const elements = document.querySelectorAll("div.article > h1");
Description:

You don't need jQuery to find HTML elements with CSS selectors. With the querySelectorAll vanilla JavaScript method, you can get the same result.  

The querySelectorAll() method returns a static NodeList representing a list of the document's elements that match the specified group of selectors. The selector must be a valid CSS selector string.

Share "How to select HTML elements by CSS selectors in vanilla JavaScript?"