Michael
Michael

Reputation: 719

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 ?

Upvotes: 3

Views: 3680

Answers (1)

Adil
Adil

Reputation: 148110

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";

Upvotes: 5

Related Questions