I need to turn on/off audio by 2 buttons. The code below workes for 1 button, but not for 2. Need to be made when you click on one button, the audio would turned on and when click goes on the other button it switched off. .audio-button - is an image.
<script>
let audioButton = document.querySelector(".audio-button");
audioButton.addEventListener('click', function(){
var audio = document.getElementById("audio");
if (audio.paused) {
audio.play();
}else{
audio.pause();
// audio.currentTime = 0
}
});
//audio-clicked
audioButton.addEventListener('click', function(){
audioButton.classList.toggle('toggle-pause');
});
</script>
<audio id="audio" volume="0.2" src="song.mp3"></audio>
<script>
var audio = document.getElementById("audio");
audio.volume = 0.1;
</script>