When a user clicks on a buttone it plays audio, but when they click on another button that audio stops and it then plays audio for that button and so forth. at the moment when the page loads i also have background music which autoplays, I am trying to figure out how to stop the music playing when a new button is pressed and then that music plays as currently they overlap. Any help would be greatly appreciated.
on load background music code:
<audio autoplay="autoplay" class="bondAudio">
<source src="audio/Bond.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
button clicked audio plays code:
<script>
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'audio/Dr-No.mp3');
audioElement.setAttribute('play', 'play');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
}, true);
$('#blockLink1').click(function() {
audioElement.play();
});
});
</script>