Get the playPause function to switch icons in the browser
20:16 06 Sep 2026

I'm using fontawesome and all the icons show up just fine but the playPause function won't switch between the two icons, I have the HTML set up like this,



    
        
        Music Player
        
        
        
        
        
        
    
    
        

Sprawl

Broadcast 96

and the JavaScript,

let progress = document.getElementById("progress");
let song = document.getElementById("song");
let ctrlIcon = document.getElementById("ctrlIcon");


song.onloadedmetadata = function(){
    progress.max = song.duration;
    progress.value = song.currentTime;
    
};


function playPause(){
    if(ctrlIcon.classList.contains("fa-pause")){
        song.pause();
        ctrlIcon.classList.remove("fa-pause");
        ctrlIcon.classList.add("fa-play");
    }
    else{
        song.play();
        ctrlIcon.classList.add("fa-pause");
        ctrlIcon.classList.remove("fa-play");
        
    }
}
javascript html