Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Play audio by click on 2 buttons

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>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!