JS WEB APISChapter 7 · JS Web APIs
Creating Elements
document.createElement("li") makes a new element that is not on the page yet. Set its text and classes, then attach it with parent.append(element). Remove one with element.remove(). Turning an array of data into elements, one per item, is one of the most common jobs in front-end code.
Worked example
How it reads
createElementmakes the element in memory onlyappendis what puts it on the pagechildren.lengthcounts the elements inside the list

Cloud tip: Build all the elements first and append them in one go when you have hundreds of items; it keeps the page fast.


