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

161
Views
How can I fix trouble with event ended with jQuery?

I created a liitle pet-project like player for sounds with jQuery and have some problems with event "ended" of tag "audio". My code is working but not last function with "ended". I do not understand what is wrong. I hope a people from stackoverflow help me to confirm this problem.

Its my code:

$(document).on('click', '.button-play', function () {
  $(this).next('.play-audio').trigger('play');
  $(this).nextAll('.button-pause').toggle();
  $(this).toggle();
});
$(document).on('click', '.button-pause', function () {
  $(this).prev('.play-audio').trigger('pause');
  $(this).prevAll('.button-play').toggle();
  $(this).toggle();
  });
$(document).on('ended', '.play-audio', function () {
  $('.button-play').toggle();
  $('.button-pause').toggle();
}, false);
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The issue is because Media events - such as ended in this case - do not bubble up the DOM, so you cannot use them in delegated event handlers. Source

For the code to work you will need to attach the ended event directly to the audio element for the handler to work as you expect.

about 4 years ago · Juan Pablo Isaza Report

0

I have changed my code, now its working but only one time. This function only works once.

$(document).on('click', '.button-play', function () {
    $(this).next('.play-audio').on('ended', function () {
      $(this).prev('.button-play').toggle();
      $(this).next('.button-pause').toggle();
    });
  });
about 4 years ago · Juan Pablo Isaza Report
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!