Playing audio in HTML

HTML JavaScript

Assuming you are working with HTML5, you can embed the audio element.

<audio id="someId"> <source src="sounds/ding.wav" type="audio/wav"></source> Your browser does not support the audio element. </audio>

Then play the music based on the ID and . You have to use JavaScript getElementById('someId') as jQuery won't work.

var audio = document.getElementById('someId') // play // pause audio.pause() // restart if (audio.paused) { }else{ audio.pause() audio.currentTime = 0 }


audio element

History Jun 26, 2019