Contact Us or call 1-877-932-8228


The DOM is not JavaScript

It's important to understand that the DOM is a standard that is separate from JavaScript. It was created by the W3C to normalize the browser vendors' implementations of Dynamic HTML.

The DOM enables programmatic access to the HTML document structure for reading or modification purposes through an API. When we write code like document.getElementById('abc') we are accessing the DOM using JavaScript.

We can traverse our entire HTML document looking for specific HTML elements, which are called nodes, in the DOM. We can even create and append new elements to the DOM.

JavaScript is not the DOM

Just as the DOM is not written specifically for JavaScript, JavaScript is not written specifically for the DOM.

JavaScript is an interpreted language with a runtime execution engine. It needs a host environment to instantiate the engine and forward the JavaScript code to it. The browser is one of many hosts for JavaScript. Other hosts are Adobe Flash plugins (via ActionScript), desktop widgets (like Yahoo! Widgets, MS Gadgets, OS X Dashboard Widgets), Firefox browser add-ons, and even some kinds of electronic equipment.

All that said, the browser was the originally intended host for JavaScript and by far the most common one.

The window object

In browser scripts, the document object is actually a property of the window object, which is the default (or global) object of JavaScript in that environment. So typing window.document.body is the same as typing document.body. The DOM starts at the document object.

There are other things one may think are part of JavaScript when, in fact, they're browser-specific features, like the alert(), prompt(), setTimeout(), and open() functions. These are just methods of the window object, not part of JavaScript itself.