Play and pause one HTML5 audio element at a time via jQuery?

Var curPlaying; $(function() { $(". Playback"). Click(function(e) { e.preventDefault(); var song = $(this).

Next('audio')0; if(curPlaying) { $("audio", "#"+curPlaying)0.pause(); } if(song. Paused) { song.play(); } else { song.pause(); } curPlaying = $(this).parent()0. Id; }); }); That should work.

EDIT: var curPlaying; $(function() { $(". Playback"). Click(function(e) { e.preventDefault(); var song = $(this).

Next('audio')0; if(song. Paused){ song.play(); if(curPlaying) $("audio", "#"+curPlaying)0.pause(); } else { song.pause(); } curPlaying = $(this).parent()0. Id; }); }).

1 ...I am such a hypocrite... – NeXXeuS Apr 19 at 19:59 @NeXXeuS and I love you for it. Your function plays the songs while pausing other active songs perfectly.. but no longer pauses the song that's playing if you click on it again. – technopeasant Apr 19 at 20:08 I did...not understand that... – NeXXeuS Apr 19 at 20:30 @NeXXeuS.My mistake, let me clarify.

The page loads and all players are silent, as they should be. Clicking on one plays it appropriately, and clicking on a different one while it's playing pauses the first and plays the new one (perfect!). The only problem is that clicking on whichever one is playing no longer pauses it.

– technopeasant Apr 19 at 20:33 I'm guessing here, but try the edit to my answer I just made. – NeXXeuS Apr 19 at 21:02.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send