Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you change video src using jQuery?

Tags:

html

jquery

video

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.

like image 859
Aximili Avatar asked Oct 20 '10 23:10

Aximili


People also ask

How to change video src in jQuery?

click(function () { $("#divVideo video"). attr({ "src": $(this). data("item"), "autoplay": "autoplay", }) }) }, 2000); } }); here ". imgthumbnew" is the class of images which are thumbs of videos, an extra attribute is given to them which have video url.

How do I change the src of a video tag?

To change source on HTML5 video tag with JavaScript, we an set the src property of the video element. const changeSource = (url) => { const video = document. getElementById("video"); video. src = url; video.

How add src attribute in jQuery?

Answer: Use the jQuery attr() Method You can use the attr() method to change the image source (i.e. the src attribute of the <img> tag) in jQuery. The following example will change the image src when you clicks on the image.

What is src in video tag?

The src attribute specifies the location (URL) of the video file.


1 Answers

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

like image 165
Šime Vidas Avatar answered Sep 28 '22 05:09

Šime Vidas