views:

13

answers:

1

How do you change the src of a HTML5 video tag using jQuery?

I got this HTML:

<div id="divVideo">
  <video controls>
    <source src="test1.mp4" type="video/mp4" />
  </video>
</div>

This doesn't work:

var videoFile = 'test2.mp4';
$('#divVideo video source').attr('src', videoFile);

It changes the src if I inspect it using firebug, but does not actually change the video being played.

I read about .pause() and .load(), but I'm not sure how to use them.

+2  A: 

Try $("#divVideo video")[0].load(); after you changed the src attribute.

Šime Vidas