All About Code

5 days ago

Here is the JavaScript.

function playAudio(url) {
new Audio(url).play();

Here is the HTML.

<img src="image.png" onclick="playAudio('mysound.mp3')">

If you experience a delay, use var audio = new Audio(url); once on page load. Then trigger it by audio.currentTime = 0;;. Resetting current time is only needed if the sound is…