title: Uncaught ReferenceError: X is not defined
body: <p>This code is being used on a Chrome Extension.
  When I call the <code>&quot;showOrHideYT()&quot;</code> function, I get a</p>
  <blockquote>
  <p>&quot;Uncaught ReferenceError:  showOrHideYT is not defined | (anonymous
  function) | onclick&quot;</p>
  </blockquote>
  <p>This code will search for youtube links in a page, and it will add a button (it's really a div with an event) next to the link to show the iframe with the embedded video, pretty much like Reddit Enhancement Suite. Consider the code, per se, incomplete. I just want to know what am i missing when i call the <code>&quot;showOrHideYT(frameZES12345)&quot;</code> function.</p>
  <p>if needed, i can provide manifest.json.</p>
  <p>Thanks</p>
  <pre><code>function showOrHideYT(id)
  {
      var YTvidWidth  = 420;
      var YTvidHeight = 315;
      frameYT=getElementById(id);
      console.log(frameYT.style.visibility);
      if (frameYT.style.visibility == &quot;hidden&quot;)
          {
          frameYT.style.width = YTvidWidth+&quot;px&quot;; 
          frameYT.style.height = YTvidHeight+&quot;px&quot;; 
          frameYT.style.visibility = &quot;visible&quot;;
          }
      if (frameYT.style.visibility == &quot;visible&quot;)
          {
          frameYT.style.width = &quot;0px&quot;; 
          frameYT.style.height = &quot;0px&quot;; 
          frameYT.style.visibility = &quot;hidden&quot;;
          }
  };
  
  
  // DOM utility functions
  function insertAfter( referenceNode, newNode ) {
      if ((typeof(referenceNode) == 'undefined') || (referenceNode == null)) {
          console.log(arguments.callee.caller);
      } else if ((typeof(referenceNode.parentNode) != 'undefined') &amp;&amp; (typeof(referenceNode.nextSibling) != 'undefined')) {
          if (referenceNode.parentNode == null) {
              console.log(arguments.callee.caller);
          } else {
              referenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );
          }
      }
  };
  function createElementWithID(elementType, id, classname) {
      obj = document.createElement(elementType);
      if (id != null) {
          obj.setAttribute('id', id);
      }
      if ((typeof(classname) != 'undefined') &amp;&amp; (classname != '')) {
          obj.setAttribute('class', classname);
      }
      return obj;
  };
  /////////////////////////////////////// 
  
  
  
  $(document).ready(function() {
  
      
      var vidWidth    = 420;
      var vidHeight   = 315;
      var linksSemID  = document.getElementsByTagName(&quot;a&quot;) ;
  
      for (var i = 0; i &lt; linksSemID.length; i++){
          if (/id=$/.test(linksSemID[i].href)) links[i].href += &quot;1&quot;;
      }
  
      i=0;
      var youTubeRegExp = /(?:v=)([\w\-]+)/g;                 
      var forEach = Array.prototype.forEach;                  
      var linkArray = document.getElementsByTagName('a');     
  
      forEach.call(linkArray, function(link){                 
          linkArray.id=&quot;zes&quot; + i++;                           
          
          var linkTarget = link.getAttribute('href');         
          if (linkTarget!=null)                               
              {
              if (linkTarget.search(youTubeRegExp) !=-1)      
                  {
                  
                  console.log (linkTarget);
                  idVideo=linkTarget.match(/(?:v=)([\w\-]+)/g);
                  //idVideo = idVideo.replace(&quot;v=&quot;, &quot;&quot;);      
                  
                  //add buton
                  botaoMais = document.createElement('DIV');
                  botaoMais.setAttribute('class','expando-button collapsed video');
                  botaoMais.setAttribute('onclick','showOrHideYT(frameZES'+ i +')');
                  insertAfter(link, botaoMais);
  
                  
                  
                  //add iframe
                  ifrm = document.createElement('IFRAME'); 
                  ifrm.setAttribute('src', 'http://www.youtube.com/embed/'+ idVideo); 
                  ifrm.style.width = '0px'; 
                  ifrm.style.height = '0px'; 
                  ifrm.style.frameborder='0px';
                  ifrm.style.visibility = 'hidden';
                  ifrm.setAttribute('id', 'frameZES' + i);
                  insertAfter(link, ifrm);
                  
                  }
              }
      });  
  
  });
  </code></pre>