0

I want to just change the color of my li tag which is within a ul tag with the class collection.

let btn = document.querySelector(".btn");
let item = document.getElementsByClassName("collection");
btn.addEventListener("click", function() {
  item.style.background = "black";
});

I am guessing there is a syntactical error that is tripping me here. What is wrong with this piece of code?

  • You have to iterate over the (live) collection of elements to update the style of each `item` individually. – David Thomas Jan 04 '20 at 22:22
  • You could use `document.querySelectorAll(".collection")` but still you have to iterate over the collection of elements. – bron Jan 04 '20 at 22:29

0 Answers0