HTMLElement is the base interface for most concrete HTML elements. It provides shared properties such as innerText, hidden, classList, dataset, and style; specialized interfaces such as HTMLInputElement add element-specific APIs. section 6.2.1 section 7.5.1
Use element objects to read or change content, update styles, manage children, and remove or move nodes. DOM changes happen synchronously, but rendering waits until the current task finishes and the main thread can repaint. section 6.1
Prefer native element APIs for common tasks:
- Use classList and dataset instead of manually parsing class and data attributes. section 6.2.1
- Use specialized properties such as input.value or a.href instead of parsing strings; keep visual styling in CSS classes where practical. section 6.2.1
const btn = document.createElement("button");
btn.classList.add("primary");
btn.dataset.action = "save";
btn.innerText = "Save";
document.body.append(btn);
console.log(btn.dataset.action); // "save"
Creates a button, assigns a class and data value, sets its text, and appends it to the document. section 6.2.1
Table 6.2 Most used public methods and properties from HTMLElement to browse the DOM
| Property / Method | Return type | Explanation |
|
Node (often HTMLElement or Document) |
Returns the direct parent node of the element. It can be the document or another element. |
|
HTMLElement (or |
Similar to |
|
HTMLCollection |
Returns all child elements (only element nodes, excludes text and comments). |
|
NodeList |
Returns all child nodes, including text nodes, comments, and elements. |
|
Node (or |
Returns the first child node, which could be a text node, comment, or element. |
|
HTMLElement (or |
Returns the first child that is specifically an element. |
|
Node (or |
Returns the last child node of the element. |
|
HTMLElement (or |
Returns the last child that is specifically an element. |
|
Node (or |
Returns the node immediately before the element, including text nodes. |
|
HTMLElement (or |
Returns the element immediately before the element, ignoring text nodes. |
|
Node (or |
Returns the node immediately after the element, including text nodes. |
|
HTMLElement (or |
Returns the element immediately after the element, ignoring text nodes. |
|
HTMLElement (or |
Returns the nearest ancestor (including the element itself) that matches the CSS selector. |
Compare parent and child traversal properties, noting that some return only elements while others include text and comment nodes. section 6.2.5


