1var audio = new Audio("soundfile.wav");
2
3document.onclick = function() {
4 audio.play();
5}
1<script>
2function play() {
3 var audio = new Audio('https://interactive-examples.mdn.mozilla.net/media/examples/t-rex-roar.mp3');
4 audio.play();
5}
6</script>
7<button onclick-"play();">PLAY MY AUDIO</button>
1<audio id="audio" src="http://www.soundjay.com/button/beep-07.wav" autoplay="false" ></audio>
2<a onclick="playSound();"> Play</a>
3<script>
4 function playSound() {
5 var sound = document.getElementById("audio");
6 sound.play();
7}
8</script>