play audio on button click html
var sound = new Audio("file.wav");
button.addEventListener('click',()=>{
sound.currentTime = 0;
sound.play();
});
play audio on button click html
var sound = new Audio("file.wav");
button.addEventListener('click',()=>{
sound.currentTime = 0;
sound.play();
});
click play sound
<!doctype html>
<html>
<head>
<title>Audio</title>
</head>
<body>
<script>
function play() {
var audio = document.getElementById("audio");
audio.play();
}
</script>
<input type="button" value="PLAY" onclick="play()">
<audio id="audio" src="https://interactive-examples.mdn.mozilla.net/media/cc0-audio/t-rex-roar.mp3"></audio>
</body>
</html>
Run code snippet
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us