0

I have tried to change "src" in the video tag in HTML with jQuery (FYI: I am using Video.js).

Tried with this code but it did not work. Please help me :.(

$(document).ready(function(){
  $(".click_me").click(function(){
    $('.video_div video source').attr('src', "small.mp4");
    $("video")[0].load();
  });
});
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Test</title>
    <script src="jquery-3.2.1.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.2.1.min.js"></script>
    <script src="http://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script>
    <script src="script.js"></script>
    <link href="http://vjs.zencdn.net/6.2.7/video-js.css" rel="stylesheet">
  </head>
  <body>
    <video id="my-video" class="video-js" controls preload="auto" width="640" height="264" poster="MY_VIDEO_POSTER.jpg" data-setup="{}">
      <source src="MY_VIDEO.mp4" type='video/mp4'>
      <source src="MY_VIDEO.webm" type='video/webm'>
      <p class="vjs-no-js">
        To view this video please enable JavaScript, and consider upgrading to a web browser that
        <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a>
      </p>
    </video>
    <script src="http://vjs.zencdn.net/6.2.7/video.js"></script>
  </body>
</html>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • https://stackoverflow.com/questions/5235145/changing-source-on-html5-video-tag/ same question.. check the modernizr answer – Rachel Gallen Sep 12 '17 at 22:19
  • also https://stackoverflow.com/questions/3732562/can-i-use-javascript-to-dynamically-change-a-videos-source (points to the above question actually in an comment/edit) – Rachel Gallen Sep 12 '17 at 22:20

0 Answers0