title: Youtube iframe API does not work as expected
body: <p>In one of my modals I want to display a youtube video. Which one (which ID) depends on which button is used to open the model.</p>
  
  <pre><code>&lt;button class='yt-play' data-yt='xxxxxx'&gt;Play video&lt;/button&gt;
  </code></pre>
  
  <p>In my javascript file I'm using the YT player-api to generate an iframe; i followed the <a href="https://developers.google.com/youtube/iframe_api_reference#Getting_Started" rel="nofollow noreferrer">Getting started on google developers</a>.</p>
  
  <p>So In the modal I added an <code>&lt;div id='player'&gt;&lt;/div&gt;</code> and This is my included javascript:</p>
  
  <pre><code>var tag = document.createElement('script');
      tag.src = "https://www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  var player;
  
  function onYouTubeIframeAPIReady() {
    player = new YT.Player('player', {
      videoId: '5ulO97zuVF0', //- just a temporary id
    });
  }
  
  // on document ready do some jQuery things, 
  // like adding an event handler to the button. 
  $(document).ready(function (){
  
     $('.yt-play').click(function(ev){
          ev.preventDefault();
          var videoid = $(this).data('yt');
  
          player.loadVideoById(videoid);
          $('#yt-player').modal('show');
          player.playVideo();
  
      });
  
  });
  </code></pre>
  
  <p>The click-handler on yt-play should load the video by means of player.loadVideoById() as stated <a href="https://developers.google.com/youtube/iframe_api_reference#loadVideoById" rel="nofollow noreferrer">here in the documentation</a>. </p>
  
  <p>But somehow I get an javascript error: <code>TypeError: player.loadVideoById is not a function</code></p>
  
  <p>If I dump the player-object in the console I'm getting a nice player object; which holds amongst many others the loadVideoById function. At least it looks like it:  </p>
  
  <p><img src="https://i.stack.imgur.com/Wb119.png" alt="console screenshot"></p>
  
  <p>What's the reason the new video is not loaded?</p>