Lesson 9 of 55
javascriptManipulating the DOM – Creation, Insertion & Removal
12 mins
Course progress16%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 9 of 55
javascript12 mins
Keep these ideas in mind as you work through the lesson.
Creating elements:
const div = document.createElement('div');
Setting attributes & content:
div.id = 'myDiv';
div.className = 'card';
div.textContent = 'Hello';
Appending / inserting:
document.body.appendChild(div);
// insert before an existing node
parent.insertBefore(newNode, referenceNode);
Removing:
div.remove(); // modern
parent.removeChild(div); // legacy