Build a Favorite Icon Toggler - Build a Favorite Icon Toggler

Tell us what’s happening:

When I click one button, all three are activated. I tried a for loop and the same thing happens. What’s the error?

const nodeList = document.querySelectorAll(“.favorite-icon”); //It is an array

nodeList.forEach(function (item){
item.addEventListener(“click”, changeColor);
});

const iconList = document.querySelectorAll(“.empty-heart”);

function changeColor() {
iconList.forEach(function(item){
item.innerHTML = “:heart:”;
item.classList.toggle(“filled”);
})
}

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:139.0) Gecko/20100101 Firefox/139.0

Challenge Information:

Build a Favorite Icon Toggler - Build a Favorite Icon Toggler

this is changing all of the elements, not only the one clicked

Thanks, Let’s see if I can fix it.

The error was simple:
<button class="favorite-icon"><i class="empty-heart">"&#9825;"</i></button>

and now,

<button class="favorite-icon empty-heart">"&#9825;"</button>.

More easy!!!`