DOM stands for Document Object Model.
In simple words:
It allows JavaScript to:
| Term | Meaning | Example |
|---|---|---|
| Root | Top of the DOM tree | document |
| Parent | Element above another element | <div> is parent of <p> |
| Child | Element inside another element | <p> inside <div> |
| Sibling | Elements at the same level (same parent) | Two <p> inside same <div> |
| Node | Every part of DOM (element, text, comment) | Any <p>, text node, or comment |
HTML DOM API is a set of methods and properties that JavaScript uses to interact with HTML pages.
It allows JavaScript to:
HTML:
JavaScript:
In HTML, every tag is called an element.
✅ Each element consists of a tag and its content.
✅ JavaScript can use the DOM to access these elements and change their content, style, or attributes.
| Selector | What it Does | Example / Notes |
|---|---|---|
| getElementById() | Selects a single element by its unique ID | document.getElementById("demo") → only one element |
| getElementsByClassName() | Selects all elements with a specific class | document.getElementsByClassName("box") → list of elements |
| getElementsByTagName() | Selects all elements with a specific tag | document.getElementsByTagName("p") → all paragraphs |
| querySelector() | Selects the first element matching a CSS selector | document.querySelector(".box") → first element |
| querySelectorAll() | Selects all elements matching a CSS selector | document.querySelectorAll(".box") → all elements |