Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT DOM / CHAPTER 04 / Learn / LESSON 08
createElement("li") builds a new element in memory. textContent sets its text. appendChild (or append) attaches it to a parent — otherwise it stays invisible.
Mini example:
const list = document.querySelector("#list"); const item = document.createElement("li"); item.textContent = "taxi"; list.appendChild(item);
Common mistake: createElement without append; or writing an HTML string via innerHTML instead of plain textContent.
<ul id="list"></ul><p id="meta">items</p>The element must be attached to appear.
Press Run — HTML loads in a sandbox iframe; Stop removes the iframe (also kills infinite loops).
›