Czy może mi ktoś wytłumaczyć co robię nie tak? Mam 3 karty na stronie. Pobieram je za pomocą querySelectorAll i chce wywołać na każdym elemencie funkcję, przez użycie foreach. Dostaję taki o to błąd:
Uncaught TypeError: cards.foreach is not a function
at HTMLInputElement.changePricing
const toogle = document.getElementById("toogle");
const cards = document.querySelectorAll(".card");
console.log(cards);
const changePricing = () => {
if (toogle.checked) {
console.log("is checked");
cards.foreach(item => {
item.lastChild.style.display = "none";
item.firstChild.style.display = "auto";
});
} else {
cards.foreach(item => {
console.log("is not checked");
item.lastChild.style.display = "none";
item.firstChild.style.display = "auto";
});
}
};
toogle.addEventListener("click", changePricing);