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

1
  • FYI JSFiddle makes use of an IFrame, and run is simulated most probably by reloading the source. Commented Jul 17, 2015 at 19:28

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.