Document Object Model DOM in JavaScript
Document Object Model DOM in JavaScript
Object Model
(DOM) in
JavaScript
The Document Object Model (DOM) is a programming interface for
HTML documents. It represents the structure of a document as a
tree-like hierarchy, allowing developers to access and manipulate
web page content, structure, and style using JavaScript.
Introduction to the DOM
1 Structure
The DOM represents an HTML document as a tree
structure, where each HTML element is a "node" connected
in a hierarchy, similar to a family tree.
2 Manipulation
It provides a way for programs to dynamically access and
update the content, structure, and style of documents.
How the DOM Works
Root Element
The topmost node is the document object, representing the entire HTML document.
Parent-Child Relationships
Elements can contain other elements, creating a hierarchical structure of parent and child nodes.
Node Types
The DOM includes various node types: elements, text nodes, and attributes.
Accessing the DOM with JavaScript
Modifying Content
Removing Elements
Some Examples
getElementById()
querySelector()
classList