Creating and Appending Elements
JavaScript allows you to create new elements and append them to the document.
Creating Elements
You can create new elements using the createElement
method.
let newElement = document.createElement("div");
Appending Elements
To add a new element to the document, use methods like appendChild
, insertBefore
, or insertAdjacentElement
.
parentElement.appendChild(newElement);
Continuing the tribute page example, let’s try to add some list HTML elements using JavaScript.
Task
- Add the values in the array otherServices as list items for the list with the id list using the for loop.