JavaScript: Browser Window Object, Document Object Model

By Xah Lee. Date: . Last updated: .

There are 3 kinds of objects you work with when using JavaScript for website:

Browser Window Object

The browser's window object is the global object. Anything you do with a browser, is done via the window object.

Google Chrome console window object 2014
Google Chrome console showing the window object

In browser console, type window to view this object's properties. 〔►see JavaScript: How to Use Browser's JS Console

When you define a global variable in JavaScript in browser, it becomes a property of the window object. 〔►see JavaScript Variable Scope: Function Level vs Block Level

The window object has important properties. For example:

You don't need to prefix window. to use its methods or properties, because its a global object. For example, alert("3") is same as window.alert("3")

The window object also has a property key "window", so window.window refers to itself. and window.window.window, window.window.window.window all refer to window.

The window object and its system is called Browser Object Model (BOM).

Document Object Model (DOM)

One of the most important property of window is window.document. This is the document object.

The document object represent the HTML/XML document in the browser window.

The document object contains methods to manipulate HTML elements and styles. This object system is called DOM (Document Object Model).

The DOM allows you to:

  1. Insert element. 〔►see JavaScript: Create HTML Element
  2. Remove element. 〔►see JavaScript: Remove HTML Element
  3. Change element's attributes. (such as class, id, name, width, etc.) 〔►see JavaScript: Set Element's Attribute Value
  4. Change element's content. 〔►see JavaScript: Change Element's Content
  5. Change element's CSS style. 〔►see JavaScript: Change CSS

〔►see JavaScript: Basic DOM Methods

Web Scripting Overview Topic

  1. JavaScript: Browser Window Object, Document Object Model
  2. JavaScript: Intro to Event-Based Programing
  3. JavaScript Execution Order
  4. JavaScript: What Does Live Object Mean?
  5. JavaScript: Array vs NodeList vs HTMLCollection
  6. JavaScript: DOM Whitespace Nodes
Like what you read? Buy JavaScript in Depth
or, buy a new keyboard, see Keyboard Reviews.