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

121
Vistas
Find the closest DOM element to currently ran script

I'm currently rebuilding a user 'subscribe' form used to be loaded synchronously and document.write was used to append everything to the page, but I have to load jQuery async first so I had to stick to DOM manipulation. What I'm trying to do is append the main element of this form where everything else is nested. So in my form I create all of nodes using document.createElement and then append them with container.appendChild(content)

<div class="main">
 <!-- form contents -->
</div>

Now, I can append everything inside the form to .main but how do I append this form in a specific place in the document itself? For example

<body>
  <div class='container'>
    <script src='form_script.js'>
      <!-- div.main to be generated in div.container -->
    </script>
  </div>
</body>

How can I select the element that like in function .closest() is the DOM node that the script was pasted into?

about 4 years ago · Juan Pablo Isaza
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