function update() { var html = document.getElementById("html"); var css = document.getElementById("css"); var code = document.getElementById("code").contentWindow.document; document.body.onkeyup = function(){ code.open(); code.writeln(html.value+""); code.close(); }; document.addEventListener("DOMContentLoaded", function(){ code.open(); code.writeln(html.value+""); code.close(); }); }; update();