0

I am trying to create a clone of jsbin or jsfiddle. I have written a javascript function which ammends code to the HTML when the run button is clicked. The HTML and CSS code updates and runs fine but I cannot seem to get the javascript to work. I am trying to get an alert('hello world') to pop up when I press the run button

The following is the javascript code

document.getElementById("run").onclick=function(){
    var x = document.getElementById('updateable');
    var html= "<p>Hello World</p>";
    var css="<style>p {color:green;}</style>";
    var js="<script> alert('hello world') <\/script>";
    x.innerHTML=html + css +js;
}

https://jsfiddle.net/7oskp4wa/2/

I have included my jsfiddle and hope it helps

Cœur
  • 37,241
  • 25
  • 195
  • 267
alan
  • 11

1 Answers1

0

How about using an iframe? (Like jsfiddle). However what your trying to acomplish is doable. You can put all the script into a function and execute it when the html loades.

Aryeh Armon
  • 2,137
  • 2
  • 22
  • 37