There are blocks with the files contained in them. It is necessary that by clicking on a block with the "play" class, the playback of other audio is stopped, and the audio contained in the block that was clicked is played or paused via jQuery

<div class="play"> <img src="img/icons/play.png"> <audio src="media/music/Robbie Williams - Feel.mp3"></audio> </div> 

trying to do so

 $('.play').click(function() { audioElement.pause(); $(this).find('audio').trigger("play"); }); 

if you remove

 audioElement.pause(); 

the audio is played but the other is not interrupted

Thank you in advance for your help

  • If you want to avoid simultaneous playback, will it not be easier on the page to use only one audio element, and set different src for it? - Oleg

1 answer 1

What is audioElement ?

 $('.play').click(function() { $('audio').not($(this).find('audio')).trigger("pause"); $(this).find('audio').trigger("play"); }); 
  • Thank you. And what is possible in $ ('audio'). Not ($ (this) .find ('audio')). Trigger ("pause"); add, what would not pause was, and dropped to the beginning, and when you click again to start again? - Artem
  • @ Artem Please. Let's do this. You will accept this answer - a "tick" on the left - and ask a new question. - Igor