Selecting DOM Elements
The DOM is a tree of all elements. JS reads and modifies it.
| Method | Returns |
|---|---|
getElementById | One element |
querySelector | First match |
querySelectorAll | All matches (NodeList) |
The DOM is a tree of all elements. JS reads and modifies it.
| Method | Returns |
|---|---|
getElementById | One element |
querySelector | First match |
querySelectorAll | All matches (NodeList) |
const header=document.getElementById('header');
const btn=document.querySelector('.btn');
const all=document.querySelectorAll('.card');
all.forEach(el=>console.log(el.textContent));
More in JavaScript