Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

159
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda