Chapter 1 deck Chapter 2 deck Chapter 3 deck Chapter 4 deck Chapter 5 deck Chapter 6 deck Chapter 7 deck Chapter 8 deck Chapter 9 deck Chapter 10 deck Chapter 11 deck Chapter 12 deck Chapter 13 deck Chapter 14 deck

The HTML DOM: Objects, Properties & Methods

6 slides · use ←/→ or Space to navigate, F for fullscreen.

Reading view

← Back to the full Chapter 6 deck

The HTML DOM: Objects, Properties & Methods
Fullscreen for presentation · Print / PDF for a handout
1 / 6
Lesson

The HTML DOM: Objects, Properties & Methods

The HTML DOM object model, its hierarchy, and the properties/methods programming interface.

The HTML DOM: Objects, Properties & Methods

What is the HTML DOM?

A standard object model and programming interface for HTML. It defines:

  • HTML elements as objects
  • Properties of all HTML elements
  • Methods to access all HTML elements
  • Events for all HTML elements

When a web page loads, the browser creates a DOM of the page. Every HTML element is accessible in JavaScript through the DOM. The HTML DOM is platform and language independent.

The HTML DOM: Objects, Properties & Methods

The HTML DOM Object Hierarchy

window        (outermost — represents the browser window)
  └─ document (each loaded HTML document)
       └─ html
            ├─ head
            └─ body
                 └─ form
                      └─ form controls (checkbox, text, ...)

The tree structure helps JavaScript navigate and manipulate every element on the page.

The HTML DOM: Objects, Properties & Methods

HTML DOM Objects — Core Reference

ObjectRepresents
DocumentThe entire HTML document
EventMouse clicks, key presses
Form & Form InputForm elements
AnchorHyperlinks (<a>)
Frame / Frameset / IFrameFrames
Additional objectRepresents
ImageHTML <img> elements
LocationCurrent page URL
NavigatorBrowser information
Option & SelectDrop-down lists
ScreenScreen size and resolution
Table / TableRow / TableDataTable structures
WindowBrowser window / frame
The HTML DOM: Objects, Properties & Methods

Properties and Methods

Methods are actions you can perform on HTML elements. Properties are values of HTML elements that you can get or set.

var txt = document.getElementById("intro").innerHTML;
//         └── METHOD ────────────────┘ └─ PROPERTY ─┘
The HTML DOM: Objects, Properties & Methods

Activity — complete the code

Distinguish methods from properties and navigate the object hierarchy.

// getElementById() is a
// innerHTML is a
 
// Object hierarchy: window -> -> html -> body
 
// Property example
document.getElementById("demo").style. = "25px";