Hey I am doing an project (musicplayer) in which I have to select all divs with classname ="songcard"
using JavaScript. But I am unable to do it . When I use addEventListener
on it, it says, 'addEvenListener is not a function'
. But when I change the queryselector all to only queryselector the first div with class name song card is selected.
This is my html code==>
<div>
<div class=" songcard ">
<img src="assests/Ik Tera by Maninder Buttar.jpg" alt="">
<div class=" bg-white text-black pl-2">
<h1 class="font-bold"> Ik Tera </h1>
Maninder Buttar
</div>
</div>
<div class=" songcard ">
<img src="assests/Dil Bechara.jpg" alt="">
<div class=" bg-white h-12 text-black pl-2">
<h1 class="font-bold"> Dil Bechara </h1>
</div>
</div>
Sorry I removed some tailwind classes to not confuse u. Ok this is my Js code
let songcard = document.querySelectorAll(".songcard");
songcard.addEventListener('click', () => {
songcard.classList.toggle('text-white')
console.log('working')
})
I researched on stackoverflow but i didn't found anything. So if you can help in my project it will be good for me.
Note = English is not my native language hence sorry.