Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

108
Views
Insert html tag and script tag dynamically from javascript

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?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!