Creating and Removing Elements
createElement makes a new element. append and appendChild add it to the page, and remove deletes it. Build lists from data by looping and appending items.
Example
const list = document.createElement("ul");
["HTML", "CSS", "JavaScript"].forEach((name) => {
const li = document.createElement("li");
li.textContent = name;
list.append(li);
});
document.getElementById("demo").append(list);
list.firstElementChild.remove();Exercise
Create a new paragraph element.
document.("p")
Quiz Test
These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.