Here is my solution in a recent project.
<!DOCTYPE html>_x000D_
<html>_x000D_
<head>_x000D_
<meta charset="UTF-8">_x000D_
<title>Sample</title>_x000D_
</head>_x000D_
<body>_x000D_
<h1 id="hello_world">Sample</h1>_x000D_
<script type="text/javascript">_x000D_
var div = document.createElement("div");_x000D_
var t = document.createElement('template');_x000D_
t.innerHTML = "Check Console tab for javascript output: Hello world!!!<br/><script type='text/javascript' >console.log('Hello world!!!');<\/script>";_x000D_
_x000D_
for (var i=0; i < t.content.childNodes.length; i++){_x000D_
var node = document.importNode(t.content.childNodes[i], true);_x000D_
div.appendChild(node);_x000D_
}_x000D_
document.body.appendChild(div);_x000D_
</script>_x000D_
_x000D_
</body>_x000D_
</html>
_x000D_