Document Object Model (DOM)
Manipulating DOM objects¶
What is the DOM?¶
-
DOM stands for Document Object Model
-
The DOM is a programming interface for HTML and XML
-
The DOM represents the structure of a document in memory
-
The DOM is an object-oriented representation of the web page
-
The DOM lets other programming languages manipulate the document
https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model
The DOM's content tree¶
When a browser such as Chrome or Firefox parses an HTML document, it builds a content tree and then uses it to display the document.
Accessing the Document¶
In JavaScript, the Document
interface represents any web page loaded in the browser and serves as an entry point into the web page's content, which is the DOM tree.
Access the document
object and its properties from the Chrome DevTools.
https://developer.mozilla.org/en-US/docs/Web/API/Document
Accessing the Elements of the DOM¶
The Element
interface represents the HTML elements loaded in the DOM tree.
CSS Selectors can also be used to query elements.
Elements can then be modified in JavaScript.
https://developer.mozilla.org/en-US/docs/Web/API/Element
Listening to DOM Events¶
DOM Events are sent to notify code of interesting things that have taken place. Each event is represented by an object which is based on the Event interface, and may have additional custom fields and/or functions used to get additional information about what happened.
Important DOM events include load
, click
, mouseenter
, etc.
The propagation of an event in the DOM can be stopped programatically.
Event handlers can also be registered from the HTML.