title: CodeMirror - "Uncaught TypeError: editor.getValue() is not a function"
body: <p>I'm relatively new with both CodeMirror and JavaScript so am trying to use them both to get to know them better. </p>
  
  <p>I previously had code that when I edited/executed, it worked and showed the proper output. Whereas the bottom doesn't do anything when I execute, and when I inspect in Chrome, it shows the error that is mentioned in the title.</p>
  
  <p>To try and explain it better here's some code:</p>
  
  <p><strong>This works</strong></p>
  
  <p>index.html</p>
  
  <pre><code>&lt;textarea id="editor" name="editor" style="display: none;"&gt;
  Some code
  &lt;/textarea&gt;
  
  ...
  
  var editor = CodeMirror.fromTextArea(document.getElementById('editor'), {
    lineNumbers: true,
    mode: 'text/html',
    autoCloseTags: true
  });
  executeCode();
  </code></pre>
  
  <p>The executeCode() function</p>
  
  <pre><code>function executeCode(){
          var text = editor.getValue();
          var ifr = document.createElement("iframe");
          ifr.setAttribute("frameborder", "0");
          ifr.setAttribute("id", "iframeOutput");  
          document.getElementById("iframewrapper").innerHTML = "";
          document.getElementById("iframewrapper").appendChild(ifr);
          var ifrw = (ifr.contentWindow) ? ifr.contentWindow : (ifr.contentDocument.document) ? ifr.contentDocument.document : ifr.contentDocument;
          ifrw.document.open();
          ifrw.document.write(text);
          ifrw.document.close();
      };
  </code></pre>
  
  <p><strong>This doesn't</strong></p>
  
  <p>index.html (No code typed into the textarea - executeCode() is the same)</p>
  
  <pre><code>$(function(){
      $.get('example.html',  function(data){
          $('textarea#editor').val(data);
          // now init codemirror
          var a = CodeMirror.fromTextArea(document.getElementById('editor'), {
              mode: 'text/html',
              tabMode: 'indent',
              lineNumbers: true,
              lineWrapping: true,
              autoCloseTags: true
          });
          executeCode();
      })
  })
  </code></pre>
  
  <p>Like I say, I'm new with both JS and CodeMirror, so chances are it's something pretty simple that I'm missing but would appreciate it if you could point out where I've gone wrong.</p>
  
  <p>Thanks in advance!</p>