Build a to-do list
Time to combine everything: read what someone types, then add it to the page. An input's text is in its value property.
document.createElement("li") makes a new list item. Set its textContent, then append it to the list so it appears on the page.
Finish by clearing the input, so the next task starts fresh.
Example
<button id="add">Add a star</button>
<ul id="list"></ul>
<script>
document.querySelector("#add").addEventListener("click", () => {
const li = document.createElement("li");
li.textContent = "Star";
document.querySelector("#list").append(li);
});
</script>
Type a task in the preview and click Add to try your list yourself.
Your tasks
0 of 3 done- Create a list item with document.createElement
- Clicking Add puts the typed task at the end of the list
- The input is cleared after adding
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
What does list.append(li) do?
Nothing printed yet.
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.