3

I want to change the video scr when play button is click my html is

<video class="mvideo" controls autoplay="autoplay">
    <source class="video" src="path.mp4" type="video/mp4" />
</video>
<button class="button">Play</button>

and my jquery is

$(document).ready(function(){
    $(".button").click(function(){
        $(".video").attr("src","videos/Funny Cats.mp4");
    })
});
Huangism
  • 15,324
  • 5
  • 45
  • 64

2 Answers2

0

The only way dynamic sources are going to work is if you apply them directly to the video tag eg:

<video class="mvideo" controls autoplay="autoplay"></video>
<button class="button">Play</button>

$(document).ready(function(){
    $(".button").click(function(){
        $("video").attr("src","videos/Funny Cats.mp4");
    });
});

http://jsfiddle.net/xEMzm/2/

Source

Community
  • 1
  • 1
Kivylius
  • 5,819
  • 11
  • 38
  • 70
-2

Try this:

$(".button").click(function(){
        var video = $(".video").get(0);
        $(video).attr("src","a");
    alert($(video).attr("src"));
})

This way you can use methods like: volume and others. Using jQuery Object you can't.