Reputation: 149
Ok I'm stumped. I've tried a few things to make this work without success. Again, I'm a beginner so I've probably overlooked something.
On my page, I have various html5 <audio>
players. I want to make it so when a user clicks any anchor tag (link) on the page, any and/or all of the audio players that are currently playing, pause their audio. How can I accomplish this with jquery?
Thank you in advance for any support!
<audio controls>
<source src="audio/Friedman_Doku.mp3" type="audio/mp3">
<source src="audio/wav/Friedman_Doku.wav" type="audio/wav">Your browser does not support the audio element.
</audio>
Upvotes: 1
Views: 1523
Reputation: 123
$(document).ready(function(){
console.log("DOM Ready");
$('a').click(function(){
$('audio').each(function() {
if(!this.paused){
this.pause();
}
});
});
});
This will make it so that when you click any a tag on the page, all audio tags will stop, hope it helps.
Upvotes: 2