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

116
Views
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
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!