0

I'm trying to inject a script into the DOM but the script is not actually ran. What am I doing wrong? The console.log is not executed.

document.getElementById('container').innerHTML = '<div class="x"><script type="application/javascript">console.log("a");</script></div>';
maephisto
  • 4,952
  • 11
  • 53
  • 73
  • Why do you need to do this? And give a demo so that we can easily figure out the problem – Gibbs Apr 23 '15 at 10:37
  • Did you try this? : `document.getElementById('container').innerHTML = '
    '; document.getElementById('x').innerHTML = '';`
    – Hkidd Apr 23 '15 at 10:39

1 Answers1

0

You can use eval() method to run dynamic scripts. But it is not recommended to run script dynamically due to security issues.