bg_image
header

Document Object Model - DOM

The Document Object Model (DOM) is a standardized interface provided by web browsers to represent and programmatically manipulate structured documents, especially HTML and XML documents. It describes the hierarchical structure of a document as a tree, where each node represents an element, attribute, or text.

Key Features of the DOM:

  1. Tree Structure:

    • An HTML document is represented as a hierarchical tree. The root is the <html> element, with child nodes such as <head>, <body>, <div>, <p>, etc.
  2. Object-Oriented Representation:

    • Each element in the document is represented as an object that can be accessed and modified through methods and properties.
  3. Interactivity:

    • The DOM allows developers to modify content and styles of a webpage at runtime. For instance, JavaScript scripts can change the text of a <p> element or insert a new <div>.
  4. Platform and Language Agnostic:

    • Although commonly used with JavaScript, the DOM can also be manipulated using other languages like Python, Java, or PHP.

Examples of DOM Manipulation:

1. Accessing an Element:

let element = document.getElementById("myElement");

2. Changing Content:

element.textContent = "New Text";

3. Adding a New Element:

let newNode = document.createElement("div");
document.body.appendChild(newNode);

Important Note:

The DOM is defined and maintained by the W3C (World Wide Web Consortium) standards and is constantly updated to support modern web technologies.