I have a HTML page in which I have six buttons . Each button has an onClick event handler and onClick a sound will be played. Sounds are in mp3 format. Now when I click on any button,sound will be played but if I click on another button when the first sound is being played, then the first sound stops playing.After this,if I click on any button sound will not be played.
I am not able to understand the problem.Thank you for the help.
Here is my code.
<div
style='display: block; background-image: url(./images/backgroundImage.jpg);' >
<button class="stage1" id="button_1" style="width: 280px;height: 130px; margin-top: 40px;margin-left: 40px; background: transparent; "onclick="audio('a')" ></button>
<button class="stage1" id="button_2" style="width: 280px;height: 340px; margin-top: 20px;margin-left:960px;background: transparent; "onclick="audio('ab')"></button>
<button class="stage1" id="button_3" style="width: 220px;height: 250px; margin-top: 390px;margin-left: 40px;background: transparent; "onclick="audio('abc')"></button>
<button class="stage1" id="button_4" style="width: 220px;height: 250px; margin-top: 390px;margin-left: 300px;background: transparent; "onclick="audio('abcd')"></button>
<button class="stage1" id="button_5" style="width: 220px;height: 250px; margin-top: 390px;margin-left:560px;background: transparent; "onclick="audio('abcde')"></button>
<button class="stage1" id="button_6" style="width: 400px;height: 250px; margin-top: 390px;margin-left:840px;background: transparent; "onclick="audio('abcdef')"></button>
</div>
In Javascript:
function audio(audio_name) {
audioElement.setAttribute('src', 'audio/' + audio_name + '.mp3');
audioElement.play();
}