user439133
user439133

Reputation: 2143

JQuery - changing an audio song on click?

I read the HTML5 Audio reference on W3Schools and tried to figure out how to change songs. Their example shows changing a video. I want to do this using jquery when I click on a particular song.

The song I click on has the id #song-two

$("#song-two").click(function() {
  $("#mp3_src").src("songs/songtwo.mp3");
});

but the song does not get loaded. Any ideas?

Upvotes: 0

Views: 303

Answers (2)

Pedro Lobito
Pedro Lobito

Reputation: 98901

Have you tried?

$("#audiochange").attr("src","songs/songtwo.mp3");

You can also try to provide the full url, i.e.:

$("#audiochange").attr("src","http://yoursite.com/songs/songtwo.mp3");

References:

http://api.jquery.com/attr/

Upvotes: 1

Anik Islam Abhi
Anik Islam Abhi

Reputation: 25352

Try this

$("#song-two").click(function() {
  $("#mp3_src").attr("src", "http://example.com/new_url.mp4"​​​​)​
});

instead of

$("#song-two").click(function() {
  $("#mp3_src").src("songs/songtwo.mp3);
});

Upvotes: 2

Related Questions