Skip to content
Advertisement

How to play different audio files on a single page

I would like to play different short audio clips on a single page by using different buttons, however the code I have means that all buttons will play only the first .mp3 located in the audio folder regardless of the html code I have that specifies which button will play which audio clip (example below).

Could you help me with the code to figure out where I went wrong?

Thanks!

JavaScript
JavaScript

Advertisement

Answer

in simple way you can pass audio tag id in onclick function and then get audio tag by passed id in function:

JavaScript

js:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement