The document Object

  • The document object is your door into accessing DOM objects
  • Has a number of useful properties and methods for accessing elements
  • document.getElementById() - Gets an element with a particular id attribute
  • document.getElementsByClassName() - Gets all elements with a particular class attribute
  • document.querySelector() - Gets the first element with a CSS selector
// <h1 id="my-heading">This is a heading</h1>
const heading = document.getElementById("my-heading");
heading.textContent = "New heading text";

20 / 24