Y
Y
Yaroslav2015-02-05 10:28:35
YouTube
Yaroslav, 2015-02-05 10:28:35

How to bind YouTube play button to the element I need with a certain id using JavaScript/jquery?

Good afternoon!
It is very necessary to bind the YouTube play button to a specific element (image). How can this be done with JavaScript or jQuery? Long strangled Google but he is silent as a partisan.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
frees2, 2015-02-05
@Yarez

// vid = "b6jDJVPOivI%3Flist%3D";
var player;  function onYouTubeIframeAPIReady() 
{ player = new YT.Player('player',{ videoId:'b6jDJVPOivI',
playerVars: { autoplay: 1, html5: 1, theme: "light", modesbranding: 0,
color: "white", iv_load_policy: 3, showinfo: 0, controls: 2, 'wmode':'opaque', 'list' : ''}, }); }  
var tag = document.createElement('script');tag.src = "https://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

demo
<span onclick="player.loadVideoById('5NkDEip16RE', 0);history.pushState('5NkDEip16RE', null, '5NkDEip16RE');document.title = 'ЕЦБ отказался кредитовать Афины под залог облигаций';return false"> ◄ <img src="https://i.ytimg.com/vi/5NkDEip16RE/default.jpg" class="img_class"> <b>ЕЦБ отказался кредитовать Афины под залог облигаций</b></span>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question