The Document Object Model (DOM) is a programming interface for web documents. It represents the structure of a document as a tree of objects, allowing programs to manipulate the content, structure, and style of a document dynamically.
In web development, the DOM is used to interact with HTML, XML, or XHTML documents. It provides a structured representation of the document’s elements, such as tags, attributes, and text content, as objects that can be accessed and manipulated using programming languages like JavaScript.
Example: Consider the following HTML document:
<!DOCTYPE html>
<html>
<head>
<title>DOM Example</title>
</head>
<body>
<h1>Hello, World!</h1>
<p>This is a paragraph.</p>
</body>
</html>
In this document, the <html>
, <head>
, <body>
, <h1>
, and <p>
elements are represented as nodes in the DOM tree.