Upload content into a DIV using JavaScript

1

I need to load the video.html page in the div with video id using JavaScript. I have the following script:

function video() {
    $.ajax({
        url: "video.html",
        cache: false,
        success: function(html){
            $("#video").html(html);
        },
    });
}
And the following HTML:
 <div id="video">

</div>
<br/>
    <button onclick="video()">Carregar</button>

But when I click the "upload" button nothing happens.

    
asked by anonymous 21.07.2015 / 20:39

1 answer

1

There are better ways to do this, take a look here: link .

It also has this API that can help you with inserting videos: link

Note: If youtube video, you will not be able to do that.
But for a video embedded in html, try calling your method this way:

$(document).ready(function() {
 $('button').on('click', function() {
       $("#video").load("video.html");
   });
});

And in your HTML body:

 <div id="video"><!-- //aqui seu video --></div>
 <br />
 <button>Carregar</button>

If the video is from youtube, you can load it into an iframe, passing the URL at the click of the button.

    
22.07.2015 / 21:06