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

Sure,

  1. You can set the src attribute on the source element:

    document.querySelector("#myVideoTag > source").src = "http://example.com/new_url.mp4"
    

    Or using jQuery instead of standard DOM methods:

    $("#myVideoTag > source").attr("src", "http://example.com/new_url.mp4"​​​​)​
    
  2. Then you need to call the load method on the video element:

    videoElement.load()

Leave a Comment