please help with this quiz. I've wrtitten this code: '''let listItems = document.getElementsByTagName('ul'); '''
but it tells ms it's wrong! What am I wrong?
Tijo Thomas9,737 Points
If you watch the previous video you learn about the .querySelector() and .querySelectorAll() methods. In this case you want to use .querySelectorAll() and the code should look like this:
let listItems = document.querySelectorAll("#rainbow li");
Just a note, when trying to post code snippets in the forum you need to use backticks and not apostrophes in order for the code to be formatted. The backtick key is should be to the left of the "1" key on your keyboard. For proper syntax highlighting you need to specific the language of the code after the first 3 backticks. Here is a link that shows what I mean. Just scroll down to the Inline code and block code section.
On the examples of the video it didn't mention that we had to add the li tag after id. Why now is a MUST to add li after id. Its only one id= "rainbow" on the index.html???? Or only on querySelector() it's not necessary??
Is it wrong to use document.getElementsByTagName??
Jonathan GrieveTreehouse Moderator 87,800 Points
What you want to do is target a specific element.
In JS you can target elements in the same way as you would with CSS by using query selector. You want to target the list items inside the unordered list with the #id rainbow.