Use CSS Queries to Select Page Elements6:10 with Guil Hernandez
querySelectorAll() are the most flexible of all the DOM selector methods. They accept ID's, classes, tag names, and just about any valid CSS selector.
- Locating DOM elements using selectors
- CSS selectors – MDN
HTMLCollection and NodeList
CSS selectors target the HTML elements on our web pages that we want to style. If you'd like to learn more about CSS selectors, including pseudo-class selectors, review the CSS Selectors course on Treehouse.
The following targets an input element that's:
<input type="submit">. Input elements of type
submit are rendered as buttons.
const btnSubmit = document.querySelector("input[type='submit']");
The following selects the "odd"
<li> elements in a list: 1, 3, 5, etc.
const itemsOdd = document.querySelectorAll("li:nth-child(odd)");
You need to sign up for Treehouse in order to download course files.Sign up