Insert dynamically string containing script into HTML and executing it dynamically - Javascript jQuery

Javascript examples for jQuery:String

Description

Insert dynamically string containing script into HTML and executing it dynamically

Demo Code

ResultView the demo in separate window

<html>
 <head> 
  <meta name="viewport" content="width=device-width, initial-scale=1"> 
  <script type="text/javascript" src="https://code.jquery.com/jquery-compat-git.js"></script> 
  <script type="text/javascript">
var jsCode = '<script>var executeTest = function(){ console.log("This is a test."); }</script>';
$('head').append(jsCode);

      </script> 
 </head> // w ww .ja va 2s. c  o  m
 <body> 
  <script>executeTest();</script>  
 </body>
</html>

Related Tutorials