title: Uncaught TypeError: Cannot read property 'innerHTML' of undefined
body: <p>I have been sctatching my head with this one, I am usually a jQuery chap, however I have a Magento extension that uses prototype and am a bit lost on how to fix this error:</p>
  
  <p>I am getting the error: <code>Uncaught TypeError: Cannot read property 'innerHTML' of undefined</code> I am guessing because I need to check for the existence of certain HTML in the page in question (the javascript file appears on every page so might not have the relevant html every time. </p>
  
  <p>Originally I was getting a <code>spConfig undefined</code> which is why I put in the <code>if ((typeof spConfig == 'undefined') || !spConfig) {</code> line</p>
  
  <p>The original code is:</p>
  
  <pre><code>document.observe("dom:loaded", function() {
  if(spConfig.config.dynamics == 1 &amp;&amp; spConfig.config.showbottom == 1){
      $$('.product-options-bottom')[0].insert({top: new Element('p', {id:'bottom-avail', class:'availability'}).update($$('p.availability')[0].innerHTML)});
      if(spConfig.config.showship == 1){
          $('bottom-avail').insert({after: new Element('p', {id:'bottom-shipsin', class:'shipsin'}).update($$('p.shipsin')[0].innerHTML)}); }
  }
  });
  </code></pre>
  
  <p>I tried changing to </p>
  
  <pre><code>document.observe("dom:loaded", function() {
  if ((typeof spConfig == 'undefined') || !spConfig) {
  
  } else {
      if(spConfig.config.dynamics == 1 &amp;&amp; spConfig.config.showbottom == 1){
          if($$('p.availability') != 'undefined' ){
              $$('.product-options-bottom')[0].insert({top: new Element('p', {id:'bottom-avail', class:'availability'}).update($$('p.availability')[0].innerHTML)});
          }
          if(spConfig.config.showship == 1){
              if($$('p.shipsin') != 'undefined'){
                  $('bottom-avail').insert({after: new Element('p', {id:'bottom-shipsin', class:'shipsin'}).update($$('p.shipsin')[0].innerHTML)}); 
              }
          }
  }
  }
  });
  </code></pre>
  
  <p>However I still get the error <code>Uncaught TypeError: Cannot read property 'innerHTML' of undefined</code> pointing at line <code>$$('.product-options-bottom')[0].insert({top: new Element('p', {id:'bottom-avail', class:'availability'}).update($$('p.availability')[0].innerHTML)});</code></p>