The Document Object Model
Last updated
Was this helpful?
Last updated
Was this helpful?
The Document Object Model (DOM) provides a programmatic API for controlling the browser and accessing the contents of the web page. In other words, the DOM connects web pages to scripts or programming languages by representing the structure of a document—such as the HTML representing a web page—in memory. Usually, that means JavaScript, although modeling HTML, SVG, or XML documents as objects are not part of the core JavaScript language, as such.
The browser provides the following APIs:
DOM Core - finding and setting values of elements on the page
DOM Event Model - handling events that dispatch from the page
DOM Style Model - modify styles associated with elements
DOM Traversal Model and Range Models - traversing elements on a page and editing multiple elements at once
DOM HTML API - defines objects and methods representing each type of element
DOM Validation API - methods to dynamically check if documents are valid against the specs
In other words: The HTML DOM is a standard for how to get, change, add, or delete HTML elements.
HTML DOM methods are actions you can perform (on HTML Elements).
HTML DOM properties are values (of HTML Elements) that you can set or change.
Finding HTML elements by id
Finding HTML elements by tag name. The result is an array of elements
Finding HTML elements by class name. The result is an array of elements
Finding HTML elements by CSS selectors
Examples of HTML events:
When a user clicks the mouse
When a web page has loaded
When an image has been loaded
When the mouse moves over an element
When an input field is changed
When an HTML form is submitted
When a user strokes a key
Same output, but using JavaScript HTML DOM EventListener