Nearby lessons
12 of 14JavaScript HTML DOM Elements (Nodes)
📌 What are DOM Nodes?
JavaScript allows you to dynamically create, remove, or replace HTML elements (nodes) in the DOM. These operations are useful when building interactive applications that update the page without reloading it.
🆕 Creating New HTML Elements (Nodes)
You can create a new element using document.createElement() and then append it using appendChild().
Example02
📌 Creating new HTML Elements - insertBefore()
Use insertBefore() to insert a new node before an existing child node.
parent.insertBefore(newNode, existingNode)
Example03
❌ Removing Existing HTML Elements
You can remove an element using element.remove().
Example04
👶 Removing a Child Node
To remove a specific child node, use parent.removeChild(child).
Example05
🔁 Replacing HTML Elements
You can replace an existing child node with another using parent.replaceChild(newNode, oldNode).
Example06
🧠 Test Your Knowledge
3 QuestionsProgress: 0 / 3