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 IFRA
See this fiddle: http://jsfiddle.net/Y9j7R/5/
Run this code on load:
var a = document.getElementsByTagName("a"); //1
for(var i=0; i
(anchor) elements in the documenta[i]
.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./\/vi\/([^\/]+)/
means: match a substring which equals /vi/
, and group
.link
variable has a property 1
(one), which holds the value of this group. Otherwise, link
equals null
.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).onclick
property of the current anchor. Assigning a function to the onclick
property will cause the onclick event handler to be defined.player
object (as defined by the YouTube javascript API).link[1]
as a first parameter.RegExp
object