MSDN Documentation

Web Development Standards

DOM Manipulation

The Document Object Model (DOM) is a programming interface for HTML and XML documents. It represents the page so that programs can change the document structure, style, and content. The DOM is a tree-like structure, where each node represents a part of the document, such as an element, attribute, or text.

Understanding the DOM

When a web page is loaded, the browser creates a DOM representation of that page. This DOM can be modified using JavaScript, allowing for dynamic changes to the web page without requiring a full page reload.

Key Concepts

Common DOM Manipulation Methods

JavaScript provides a rich set of methods to interact with the DOM. Here are some of the most frequently used:

Selecting Elements

Creating and Appending Elements

Modifying Element Content and Attributes

Removing Elements

Live Example: Modifying Text

This text will change!

Live Example: Adding an Element

  • Item 1
  • Item 2

Best Practices

When performing DOM manipulations, consider the following: