Skip to content

Fetching elements

Course: Basics of DOM - chapter 4

There are 5 popular methods available for fetching DOM elements -

  • querySelector
  • querySelectorAll
  • getElementById
  • getElementByClassName
  • getElementsByClassName

const title = document.querySelector('h1');
console.log(title.innerHTML)

const firstTodo = document.querySelector('h4');
console.log(firstTodo.innerHTML)

const secondTodo = document.querySelectorAll('h4')[1];
console.log(secondTodo.innerHTML)