Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Append a List Item

DOM & Eventseasy

Course · Section 7: JavaScript in the Browser: DOM and Events · Lecture 76: Selecting and Manipulating Elements

The page has an empty `<ul id="list">`. Write JavaScript that appends exactly one `<li>` with the text `Item` to it.

Sample tests

Input: exactly one <li> exists
Output: assertion passes
Input: its text is 'Item'
Output: assertion passes

Hints

Common pitfalls
  • Building HTML strings instead of creating nodes invites bugs.

Learning resources

  • MDN: Document.createElement
Approach & explanation (try first)

Creating an element node and appending it adds the list item to the DOM safely.

Loading...
⌘/Ctrl + Enter

Run your code to see results.