Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
Grab DOM element after an external script has run

I have a Next.JS page that loads an external script. This external script modifies the DOM (Specifically places a div and an iframe on the page), it's a chat widget. The div that's added becomes the last child of the body, and I'm trying to grab it with document.body.lastChild. I'm running the logic in the onLoad property of Next's script component. Problem is, the timing seems to be off. It's grabbing the last child before the div is added, verified by logging.

Not sure why... I've tried running the logic in window onload listener, document onload listener, within useEffect, etc. Any ideas? I'm trying to grab the div so I can position it differently, for context. It renders in the bottom right of the screen by default.

<Script
     id="scriptid"
     src="scriptsource"
     onLoad={() => {
       functionFromScript();
       // my logic to grab the newly added div from the above function
       document.onload = () => {
       console.log('All loaded')
       const chatDiv = document.body.lastChild;
       console.log(chatDiv)
       chatDiv.style.position = 'relative';
     };
    }}>
</Script>
about 4 years ago · Santiago Gelvez
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda