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

183
Views
How to get Html5 clicked Audio element on Pause event?

the problem seems simple but I can't find a solution. I have multiple audio element in a html file. the first mission was to pause other when click on new one. so that was achieved by this code:

 var current_active_audio_element = "";

document.addEventListener('play', function (e) {
            var audios = document.getElementsByTagName('audio');
            for (var i = 0, len = audios.length; i < len; i++) {
                if (audios[i] != e.target) {                    
                    current_active_audio_element = e.target;
                    audios[i].pause();
                }
            }
        }, true);

and the code above works fine. the next objective was to make a alert or console output when one audio element was paused. I just want only clicked element not the ones which paused programmatically in the if loop in snippet above Some thing like this:

    document.addEventListener('pause', function (e) {
            var audios = document.getElementsByTagName('audio');

            //console.log("CLICKED ITEM");          
        }, true);

my html code is simple and it's like this:

<h3>Khaled</h3>
<audio controls id="Khaled" ">
    <source src="Khaled.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>
<h3>Radio 2</h3>
<audio controls id="Radio2">
    <source src="Radio2.mp3" type="audio/mpeg">
    Your browser does not support the audio element.
</audio>

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!