I want to add iftube iframe api code to my $ (document) .ready () function, but when I do this, the player doesn't seem to load when I move the code outside the document. Can anyone suggest me some or suggestions on how I can make this video appear when inside a function?
Js
$(document).ready(function() { var tag = document.createElement('script'); tag.src = "//www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { height: '390', width: '640', videoId: 'u1zgFlCw8Aw', events: { 'onReady': onPlayerReady, 'onStateChange': onPlayerStateChange } }); } function onPlayerReady() { console.log('ready'); } function onPlayerStateChange() { console.log('player changed'); } });
styler
source share