← Back to HTML DOM
Question 178
Add a Class to Every List Item
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. Usedocument.querySelectorAll("#menu li")to select every list item. 2. Loop over the result withforEachand callclassList.add("nav-item")on each item.
Expected Output:
All three <li> elements gain class="nav-item"= newline. No newline after the last line.
Hints2 available
Sign in to use hintsTopics:
HTML DOM
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · 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.