JSFiddle - React, Tailwind, and code Playground
HTML
<button id="btn">
button
</button>
JavaScript
var b = document.getElementById('btn').addEventListener('click', playSound);
var mySound;
function sound(src) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
}
function playSound(){
mySound = new sound("p90_boltpull.wav");
mySound.play();
}