Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught ReferenceError

I am attempting to play 3 songs, one after another by using the onEnded attribute in HTML5. Here is my first attempt, but I'm getting an error.

Error : Uncaught ReferenceError: src is not defined nextSong marioKart.html:49 onended marioKart.html:58

Below is my code:

<script>
function nextSong(){
    var song = document.getElementById("player");
    song.attr(src,"countdown.wav");
}
</script>
</head>

<body>
<div style="position:relative">
<audio controls autoplay="true" onEnded="nextSong()" onplay="race()" >
     <source id="player" src="startMusic.wav" type="audio/mpeg" />
</audio>

Can someone help me in achieving this ?

like image 372
Michael Avatar asked Jul 23 '26 20:07

Michael


1 Answers

You should use attr() with jQuery element but you are using with DOM object also enclose src in quotes if it is not variable.

Using jQuery object

$(song).attr('src',"countdown.wav");

Using DOM object

song.src = "countdown.wav";
like image 155
Adil Avatar answered Jul 25 '26 09:07

Adil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!