Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6664525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:37:14+00:00 2026-05-26T02:37:14+00:00

I have some thumbnails below the main video container. I will like when you

  • 0

I have some thumbnails below the main video container.
I will like when you click on each thumbnail – the associated video loads and start playing
Using the NEW YOUTUBE API IFRAME approach here

Your help or direction will be appreciated

PREVIEW ON JSFIDDLE HERE

PREVIEW LINK UPDATED***

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:37:14+00:00Added an answer on May 26, 2026 at 2:37 am

    See this fiddle: http://jsfiddle.net/Y9j7R/5/

    Run this code on load:

    var a = document.getElementsByTagName("a");            //1
    for(var i=0; i<a.length; i++){                         //2
        if(!/#ytplayer/.test(a[i].href)) continue;         //3
        var link = a[i].innerHTML.match(/\/vi\/([^\/]+)/); //4
        if(link) (function(vidId){                         //5
            a[i].onclick = function(){                     //6
                player.loadVideoById(vidId);               //7
            }                                              //8
        })(link[1]);                                       //9
    }      
    

    Detailed explanation of the code

    1. Select all <a> (anchor) elements in the document
    2. Loop through these anchors using for. During each iteration, the “current” anchor is referred through a[i].
    3. Check whether the href attribute does not (!) contain “#ytplayer” using the test method of the Regular Expression. If this condition is true (ie: the href attribute does not contain “#ytplayer“), the continue statement terminates the current iteration, and jumps to the next anchor.
    4. The innerHTML property of the current anchor is requested. The match method is used to get the video id. The Regular expression /\/vi\/([^\/]+)/ means: match a substring which equals /vi/<any consecutive non-slash chars>, and group <any consecutive non-slash chars>.
      When such a substring is found, the link variable has a property 1 (one), which holds the value of this group. Otherwise, link equals null.
    5. If the link variable is not null, an anonymous function is created (lines 5-9) and executed (line 9). The first argument of the function will be referenced through vidId (variable).
    6. Assigns a newly created function to the onclick property of the current anchor. Assigning a function to the onclick property will cause the onclick event handler to be defined.
    7. Invokes the loadVideoById method of the player object (as defined by the YouTube javascript API).
    8.  
    9. Invokes the function (created at lines 5-9), passing link[1] as a first parameter.

    References

    • for loops and the continue statement
    • Creating and calling functions in JavaScript
    • Regular Expressions (RegExp).
    • test method of the RegExp object
    • The match function in conjunction with a Regular expression
    • The innerHTML property of an element
    • The onclick event handler
    • The loadVideoById method of the YouTube JavaScript API

    Another interesting answer

    • YouTube iframe API: how do I control a iframe player that's already in the HTML?
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some thumbnails + a camera icon on a page and a main
I have some Thumbnail images .I want to display image thumbnails in a Panorama(or
I have written a search filter. It shows/hides some thumbnails in a video gallery
I display some objects that have thumbnails in two ways: one in a DataGridView,
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
I have some classes layed out like this class A { public virtual void
I have some code like this in a winforms app I was writing to
As the title really - I have some code for reordering some thumbnails in
I have the next code with some thumbnails: <div class=gallery-wrap> <div class=gallery galleryid-45 id=gallery-1>
I currently have a working gridview displaying some thumbnails. Currently, when you select an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.