- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript DOM Selectors
JavaScript DOM
JavaScript DOM Selectors
JavaScript finds elements on a page with
getElementById,querySelectorandquerySelectorAll.
Before you can change an element you have to find it.
querySelector takes a CSS selector, which makes it the most flexible choice.
Example
Example
javascript
document.body.innerHTML = '<p class="note">Hello</p>';
const note = document.querySelector(".note");
console.log(note.textContent);The output is Hello.
