0

So, I'm still new to javascript and everything. What I'm trying to do is when a small video is clicked, display it on the main big video above. This is the script so far, but I'm not sure what I need to add.

<script type="text/javascript">
    $(document).ready(function() {
        $(".littlevideo").click(function() {
            var video = $(this).closest("div").find("video").attr("src")
            $('#displayvideo').attr("src",video);
        });
    });
</script>

2 Answers 2

1

you want to do something like:

<script type="text/javascript">
$(document).ready(function() {
    $(".littlevideo").click(function() {
        var video = $(this).closest("div").find("video").attr("src")
        $('#displayvideo').append("<iframesrc="+video+"></iframe>");
    });
});

The append basically adds that HTML to the container. you do the +video+ because it adds whatever that value is, to the existing string. This is how you make it dynamic.

Sign up to request clarification or add additional context in comments.

Comments

0

We need the rest of the page (preferably), but that piece of code should do what you are wanting. Basically, the code just takes the attributes of the element being clicked on (as long as it has a class of "littlevideo") and transfers it to the #displayvideo element (I'm guessing the "big video" you're talking about). Make sure the little video's elements/tags all have class="littlevideo", and the big video player element/tag has an attribute of id="displayvideo".

2 Comments

Thanks! Is there anything I need to add to load and play the video though? It still doesn't seem to work.
There will be other code that links to the video source/URL, at least. If you post your full code, people will be able to better help.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.