Finishing the TODO App - 2
Course: DOM Part 2 - chapter 3
Let’s look at a slightly better approach of doing the same thing.
Creating a DOM element which has another DOM element inside
Section titled “Creating a DOM element which has another DOM element inside”<body> <button onclick="createComplexDomElement()">Add</button></body><script> function createComplexDomElement() { const div = document.createElement("div"); const h1 = document.createElement("h1"); h1.innerHTML = "random text"; div.appendChild(h1); document.querySelector("body").appendChild(div); }</script>
