Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

110
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda