Simple JS Live Code Execution

Here is a simple Web page that loads and executes JavaScript from a DIV in the browser. This is a very basic trial bit of code based on something Kyle Simpson (@getify on Twitter) suggested. Here it is:



  function run(){

    var scriptTag = document.createElement("script");
    var inline = document.createTextNode( document.querySelector( "#code" ).innerText );
    scriptTag.appendChild( inline );
    document.body.appendChild( scriptTag );


<div id="code" style="width: 80%; height: 50%; border: 1px solid silver;" contenteditable="true">

<button type="button" onclick="run();">Run</button>