Question

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 ?

Was it helpful?

Solution

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";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top