Reputation: 17478
My application is retrieving content from an XML file that has javascript in it. I am taking the javascript and placing it into my DOM, but the script is not executing.
How do I write javascript onto my page that will then execute?
My app goes something like this...
var javaScriptFromFile = getJS();
myDiv.innerHTML = javaScriptFromFile;
//Next, how do I execute the javascript?
//Can I make the javascript in the innerHTML self executing?
Upvotes: 0
Views: 152
Reputation: 3109
put it in a script tag insted of a div. but are you sure this is really what you want?
Upvotes: 1
Reputation: 1038850
You could eval
the javascript. Or wrap in <script>
tags before putting in the innerHTML
.
Upvotes: 1