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 LINK UPDATED***
See this fiddle: http://jsfiddle.net/Y9j7R/5/
Run this code on load:
Detailed explanation of the code
<a>(anchor) elements in the documentfor. During each iteration, the “current” anchor is referred througha[i].hrefattribute does not (!) contain “#ytplayer” using thetestmethod of the Regular Expression. If this condition is true (ie: thehrefattribute does not contain “#ytplayer“), thecontinuestatement terminates the current iteration, and jumps to the next anchor.innerHTMLproperty of the current anchor is requested. Thematchmethod 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
linkvariable has a property1(one), which holds the value of this group. Otherwise,linkequalsnull.linkvariable is notnull, an anonymousfunctionis created (lines 5-9) and executed (line 9). The first argument of the function will be referenced throughvidId(variable).functionto theonclickproperty of the current anchor. Assigning a function to theonclickproperty will cause theonclickevent handler to be defined.loadVideoByIdmethod of theplayerobject (as defined by the YouTube javascript API).link[1]as a first parameter.References
forloops and thecontinuestatementfunctionsin JavaScripttestmethod of theRegExpobjectmatchfunction in conjunction with a Regular expressioninnerHTMLproperty of an elementonclickevent handlerloadVideoByIdmethod of the YouTube JavaScript APIAnother interesting answer