CJCoding With Joseph

Add a Class to Every List Item

Select ALL list items inside the list with id="menu" and add the class "nav-item" to each one.

Platform-Provided HTML (READ-ONLY):
<ul id="menu">
  <li>Home</li>
  <li>About</li>
  <li>Contact</li>
</ul>

Steps:
1. Use document.querySelectorAll("#menu li") to select every list item.
2. Loop over the result with forEach and call classList.add("nav-item") on each item.

Expected Output:

All three <li> elements gain class="nav-item"
Topics:
HTML DOM
Code Editor
1
Tab to indent ยท Ctrl+Enter to run ยท Ctrl+Space to expand shortcuts (clog, fn, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.