title: Javascript quick way to mute youtube video iframe
body: <p>I am looking for a way to mute the video unless the user unmutes it.</p>
  
  <pre><code>&lt;iframe id="video" src="https://www.youtube.com/embed/ShPQqM50Vz0?autoplay=1&amp;showinfo=0&amp;controls=0" frameborder="0" allowfullscreen&gt;&lt;/iframe&gt;
  </code></pre>
  
  <p>I tried using this script but nothing shows up at all</p>
  
  <pre><code> &lt;div id="player"&gt;&lt;/div&gt;
  &lt;script&gt;
        var tag = document.createElement('script');
        tag.src = "http://www.youtube.com/player_api";
        var firstScriptTag = document.getElementsByTagName('script')[0];
        firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  
        var player;
        function onYouTubePlayerAPIReady() {
          player = new YT.Player('player', {
            playerVars: { 'autoplay': 1, 'controls': 1,'autohide':1,'wmode':'opaque' },
            videoId: 'ShPQqM50Vz0',
            events: {
              'onReady': onPlayerReady}
          });
        }
  
        function onPlayerReady(event) {
          event.target.mute();
        }
  &lt;/script&gt;
  </code></pre>