Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<p>Click the button to create two SOURCE elements, and append them to the AUDIO element.</p>
<audio controls id="myAudio" autoplay>
Your browser does not support the audio tag.
</audio><br>
<p id="demo"></p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction() {
  var x = document.createElement("SOURCE");
  x.setAttribute("src", "horse.mp3");
  x.setAttribute("type", "audio/mpeg");
  document.getElementById("myAudio").appendChild(x);
  var y = document.createElement("SOURCE");
  y.setAttribute("src", "horse.ogg");
  y.setAttribute("type", "audio/ogg");
  document.getElementById("myAudio").appendChild(y);
  document.getElementById("demo").innerHTML = "The audio player now works as it should. Press play to listen to the sound of a horse.";
}
</script>
</body>
<!-- Mirrored from www.mdssup.ma/jsref/tryit.asp?filename=tryjsref_source_create by HTTrack Website Copier/3.x [XR&CO'2014], Mon, 05 Sep 2022 15:37:11 GMT -->
</html>