0

Basically, I am trying to add dynamically some html and script from javascript. But the script which is being appended from javascript is not invoked or called during rendering of base html.

<html>
<head>
</head>
<body>

<div id="container" style="width:100vw;height:100vh;position:relative;"></div>

<script type="text/javascript">
! function() {
    var ht = '<script src=\'https:\/\/www.googletagservices.com\/dcm\/dcmads.js\'><\/script>'
    var target= document.getElementById("container");
    var newScript = document.createElement("div");
    newScript.innerHTML = ht
    target.appendChild(newScript);   
}();

</script>

</body>
</html>

I have tried innerHtml and appendChild both seem to be not working. I want to add a complete HTML tag(including script which cannot be changed) in the ht variable. How we can add any HTML script from javascript and render it?

0 Answers0