March March - 5 months ago 38
Javascript Question

Can I use javascript to dynamically change a video's source?

How can I change a video's source using JS?

<video id="myVideoTag" width="670" height="377" autoplay="true" controls="controls">
<source src="" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'>


Sure, you can just set the src attribute on the source element:

document.querySelector("#myVideoTag > source").src = ""

Or using jQuery instead of standard DOM methods:

$("#myVideoTag > source").attr("src", ""​​​​)​