title: CodeMirror: Javascript in iframe not working
body: <p>I am trying to built code player that shows result of html page including script in iframe. but something seems to be wrong here. it seems javascript not working every time i click button i see error in console.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
   &lt;html&gt;
       &lt;head&gt;
            &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"&gt;&lt;/script&gt;
            &lt;link rel="stylesheet" href="codemirror/lib/codemirror.css"&gt;
            &lt;link rel="stylesheet" href="codemirror/theme/solarized.css"&gt;
  
            &lt;script src="codemirror/lib/codemirror.js"&gt;&lt;/script&gt;
            &lt;script src="codemirror/mode/xml/xml.js"&gt;&lt;/script&gt;
            &lt;script src="codemirror/mode/htmlmixed/htmlmixed.js"&gt;&lt;/script&gt;
  
      &lt;/head&gt; &lt;style&gt; .CodeMirror{border:1px solid black} &lt;/style&gt;
       &lt;body&gt;
              &lt;form&gt;
           &lt;div id="editorContainer" style="width:50%"&gt;
             &lt;textarea id="code" name="code" class="CodeMirror"&gt;
  
            &lt;button id="btn" onclick="say()"&gt;hello&lt;/button&gt;
              &lt;script&gt;
  
                  function say(){
                     alert('test')
                   }
           &lt;/script&gt;
  
  
  
             &lt;/textarea&gt;
           &lt;/div&gt;
           &lt;/form&gt;
           &lt;button&gt;click&lt;/button&gt;
           &lt;iframe id="frame"&gt;&lt;/iframe&gt;
              &lt;script type="text/javascript"&gt;
              var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
                  mode: "text/html",
                  lineNumbers: true
                });
                $("button").click(function(){
  
                    var code= editor.getValue();
                    $("iframe").contents().find("html").html(code);
                })
        &lt;/script&gt;
  
    &lt;/body&gt;
    &lt;/html
  </code></pre>
  
  <p>></p>