March March - 2 years ago 91
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"'>

Answer Source

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", ""​​​​)​
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download