JS: 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 JS: How to Use Browser Console

When you define a global variable in JavaScript in browser, it becomes a property of the window object. 〔►see JS: var Name Scope

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 JS: Create HTML Element
  2. Remove element. 〔►see JS: Remove HTML Element
  3. Change element's attributes. (such as class, id, name, width, etc.) 〔►see JS: Set Element's Attribute Value
  4. Change element's content. 〔►see JS: Change Element's Content
  5. Change element's CSS style. 〔►see JS: Change CSS

〔►see JS: Basic DOM Methods

Web Scripting Overview Topic

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