+ 2
How to play an music on onclick button using JavaScript
5 odpowiedzi
+ 12
Just for completeness, you could use the Audio object to create an audio element without HTML.
var audio = new Audio( "file.mp3" );
audio.play();
+ 9
button.onclick = function(){
audio.play();
}
// button = your button
// audio = your HTML audio element
+ 9
Yes, and it is preferable use the <source> tag inside the <audio> tag with multiple extension! ;)
<!-- Classic syntax -->
<audio src = "file.mp3"> </audio>
0
so I need to code of an audio file via HTML right