<!DOCTYPE html>
<
html
>
<
head
>
<
style
>
body {
text-align: center;
}
h1 {
color: green;
}
</
style
>
<
head
>
<
body
>
<
h1
>GeeksforGeeks</
h1
>
<
h2
>HTML DOM Source Object</
h2
>
<
h3
>An example of creating a source element
</
h3
>
<
p
>Click the button to create the source element.
</
p
>
<
audio
controls
id
=
"myAudio"
autoplay>
Your browser does not support
the audio element.
</
audio
>
<
br
>
<
p
id
=
"demo"
></
p
>
<
button
onclick
=
"myFunction()"
>
Create
</
button
>
<
script
>
function myFunction() {
var x = document.createElement("SOURCE");
x.setAttribute("src", "gameover.wav");
x.setAttribute("type", "audio/mpeg");
document.getElementById(
"myAudio").appendChild(x);
var y = document.createElement("SOURCE");
y.setAttribute("src", "gameover.ogg");
y.setAttribute("type", "audio/ogg");
document.getElementById("myAudio").appendChild(y);
document.getElementById("demo").innerHTML =
"The audio player now works.";
}
</
script
>
</
body
>
</
html
>