JavaScript Load a video in separate div, using jQuery

I haven't really seen before the include library to be written directly like you did <script src="jquery library here">... And it's actually not working because with the first line where you write the src=, you're just including the library, thus in your case you didn't surround the actual code with <script> tags, but only included the library.

Try to separate it and then enclose the code into other <script> tags. Like that:

<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <script>
        $(document).ready(function () {
            $(".video").click(function (е) {
                е.preventDefault();
                var url = this.href;
                $("#mediaWindow").html('<video width="640" height="360" controls><source src="' + url + '" type="video/mp4" /></video>');
            });
        });
    </script>

Furthermore it might be confusing, the way you wrote it, if you have to change the include library in future.

Then just have the HTML like that:

<li>
<a target='_blank' href="testVideo.mp4" class="video">
<img src="play_icon.png" alt="play_video_icon" title="Video tutorial" />
Startup</a>
</li>
Answer:1

If you want to append HTML content to any div or other element y u are not using .append? like this

 <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    $(document).ready(function()
    {
        $(".video").click(function(event) 
        {
            event.preventDefault();
            var url = $(this).html(); //this will not work
            $("#mediaWindow").append('<video width="640" height="360" controls><source src="'+url+'" type="video/mp4" /></video>');
        });
    });
    </script>

also $(this).html(); is not what you need you will have to use innerHTML

Answer:2

The url which you are trying to specify is not mentioned anywhere. Clicking on the a will give the entire html, including the image tag. This is not what you need. Specify the url in the href to the a like so:

<a target='_blank' href="video/yourVideo.mp4" class="video">...</a></li>

In your javascript:

var url = $(this).attr('href'); instead of var url = this.href;

Answer:3

Just call "load" method of "video" tag whenever dynamically assigning video source.

Also you need to change var url = $(this).html(); to var url = this.href;

and change <li><a target='_blank' href="javascript: void(0)" class="video"> to <li><a target='_blank' href="testvideo.mp4" class="video">

Here's a working jsFiddle

Javascript:

$(document).ready(function()
{
    $(".video").click(function(event) 
    {
        event.preventDefault();
        var url = this.href; // Optionally you can also use -> $(this).attr('href') 
        $("#mediaWindow").html('<video width="640" height="360" controls><source src="'+url+'" type="video/mp4" /></video>');
        $("#mediaWindow video").get(0).load(); //Just make a call to load() method
    });
});

HTML:

<li>Installation
    <ul>
        <li><a target='_blank' href="vid.mp4" class="video">  <!-- Change href -->
            <img src="play_icon.png" alt="play_video_icon" title="Video tutorial" />
            Startup</a></li>
        ...
    </ul>
</li>
Answer:4

I have a namespace generator that looks like this: (As a requirement, it also needs to have prototype objects extra and default). function generateNamespace(staticMethods, prototypeMethods){ ...

I have a namespace generator that looks like this: (As a requirement, it also needs to have prototype objects extra and default). function generateNamespace(staticMethods, prototypeMethods){ ...

I am new to angularJS and am trying to use it to get data from a json file. When I run the program the console reads out there is a 404 error and that the file does not exist. Here is the angular i ...

I am new to angularJS and am trying to use it to get data from a json file. When I run the program the console reads out there is a 404 error and that the file does not exist. Here is the angular i ...

I have a site here. Here's the code from my little form... <form method="get" action="https://www.google.com/search" target="_blank"> <table border="0" cellpadding="0"> <...

I have a site here. Here's the code from my little form... <form method="get" action="https://www.google.com/search" target="_blank"> <table border="0" cellpadding="0"> <...

  1. display text text
  2. display text from text file in html
  3. display text in text box html
  4. display text on mouseover for text in html
  5. tkinter display text in text box
  6. excel if text display text

I want clocks displaying different time zones on a webpage that i am designing.For this,i have embedded the javascript files from a webiste called qlock.The HTML code is as follows: <script type="...

I want clocks displaying different time zones on a webpage that i am designing.For this,i have embedded the javascript files from a webiste called qlock.The HTML code is as follows: <script type="...

  1. css align blocks horizontally
  2. align div blocks horizontally