the font awesome icon is not changing from play to pause when i click on it i have tried a bunch of methods but this one seems to be more accurate but icon still doesnt change.please tell whats wrong with this one or provide some other method
const makeallplay= ()=>{
let smallplayicons= songplayicon.querySelectorAll("svg");
Array.from(smallplayicons).forEach((element)=>{
element.classList.remove('fa-circle-pause');
element.classList.add('fa-circle-play');
})
}
Array.from(songplayicon.querySelectorAll('svg')).forEach((element)=>{
element.addEventListener('click', (e)=>
makeallplay();
e.target.classList.remove('fa-circle-play');
e.target.classList.add('fa-circle-pause');
})
})
here is the relevant HTML code
<div class="song-item">
<img src="logos/song1.jpg" alt="1">
<span>ILLAHI</span>
<span class="song-info">3:24 <span class="songplayicon"> <i class="fa-solid fa-circle-play play "></i></span> </span>
</div>
<div class="song-item">
<img src="logos/cover2.jpeg" alt="1">
<span>The Nights</span>
<span class="song-info">3:26 <span class="songplayicon"> <i class="fa-solid fa-circle-play play "></i></span> </span>
</div>
2
Answers
Many issues.
{
songplayicon
There is not much correct in your script so I did not try to "fix" it but rewrote it from scratch
Here is a delegation version. I wrapped your items in a div
I changed to code to toggle the other icons when necessary.
The code you’ve provided is almost correct, but there is a small issue with your event listener function’s structure. You need to use curly braces to group statements inside the event listener. Here’s the corrected code:
Here are the changes made:
.songplayicon elements.
With these changes, when you click on a play icon, it should toggle between the play and pause icons as expected.