0

I have a project where I need to run code that is set using innerHTML like so:

element.innerHTML = '<script>alert("something")</script>';

When I do this, the code doesn't run. What can I do to make the code run?

Thank you! If you down vote, please tell me why so I can improve this question.

Progo
  • 3,452
  • 5
  • 27
  • 44
  • Why would you do this? Why not just execute whatever code you need. – Brad Oct 14 '14 at 02:29
  • 1
    Read http://stackoverflow.com/questions/1197575/can-scripts-be-inserted-with-innerhtml and http://stackoverflow.com/questions/13390588/script-tag-create-with-innerhtml-of-a-div-doesnt-work – j08691 Oct 14 '14 at 02:30
  • Short answer is no, check this thread for the same scenario. http://stackoverflow.com/questions/1891947/are-dynamically-inserted-script-tags-meant-to-work – RSquared Oct 14 '14 at 02:31

0 Answers0