Sitemap
courtney

courtney

The DOM: The Breakdown ⚒

2 min readApr 25, 2022

--

The Document Object Model (DOM) is an interface for web documents. A 🌳 (tree) of “node objects” that represents a webpage. These nodes allow access and change to the document. Think of the DOM like an upside down tree. The root is at the top.

Press enter or click to view image in full size

Okay, but what does that really mean…?

When your HTML is written and viewed in the browser, an option for developers is being able to access the elements panel in the browser developers tools on any website.

Get courtney’s stories in your inbox

Join Medium for free to get updates from this writer.

You can:

  • listen for clicks and scrolls
Press enter or click to view image in full size
ex: To register a scroll event handler, you call the addEventListener() method on the target element
  • add, move, remove elements, like text, images, etc.
Press enter or click to view image in full size
ex: removeChild() method
  • fetch new data
Press enter or click to view image in full size
ex: fetch API
  • and many more!

The Benefits of the DOM:

  • it allows us to interface with the DOM via JavaScript
  • the core concepts (events, elements and classes) transcend all different types of frameworks like React, Angular and Vue.
  • you can change existing nodes

How Does the DOM Work?

You can access the DOM using JavaScript and DOM programming with two variables: Window and Document objects.

  • Window Object: is an object with methods and properties attached to the DOM window.
Press enter or click to view image in full size
credit @ Wes Bos
  • Document Object: is an object inside the window that allows us to manipulate the DOM.
Press enter or click to view image in full size
credit @ Wes Bos

While there are many other concepts to the DOM, after the completion of Phase 1 at Flatiron Schools, these were key takeaways during my learning. Feel free to correct anything! Thanks for reading :)

--

--