Fetching elements
Course: Basics of DOM - chapter 4
There are 5 popular methods available for fetching DOM elements -
- querySelector
- querySelectorAll
- getElementById
- getElementByClassName
- getElementsByClassName
1. Fetching the title
Section titled “1. Fetching the title”
const title = document.querySelector('h1');console.log(title.innerHTML)2. Fetching the first TODO (Assignment)
Section titled “2. Fetching the first TODO (Assignment)”
const firstTodo = document.querySelector('h4');console.log(firstTodo.innerHTML)3. Fetching the second TODO (Assignment)
Section titled “3. Fetching the second TODO (Assignment)”
const secondTodo = document.querySelectorAll('h4')[1];console.log(secondTodo.innerHTML)