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

102
Views
How to append two HTMLElements into one Javascript

So, i have two HTMLElements that i get using:

var el1 = document.getElementById('div1')
var el2 = document.getElementById('div2');

what i want to do is merge this 2 elements that are inserted inside two containers like below:

<container-x1>
    <container-x2>
        <div id="div1">test1</div>
    </container-x2>
</container-x1>

<container-y1>
    <container-y2>
        <div id="div2">test2</div>
    </container-y2>
</container-y1>

my goal after this is to remove completely remove the container y1 and merge test 1 and test 2 into same container like this:

<container-x1>
    <container-x2>
        <div id="div2">test1  test2</div>
    </container-x2>
</container-x1>

any help? thanks in advance

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can try this:

const el1 = document.getElementById('div1');
const el2 = document.getElementById('div2');

el2.innerHTML = el1.innerHTML + ' ' + el2.innerHTML;

el1.replaceWith(el2);

document.getElementsByTagName('container-y1')[0].remove();
<container-x1>
    <container-x2>
        <div id="div1">test1</div>
    </container-x2>
</container-x1>

<container-y1>
    <container-y2>
        <div id="div2">test2</div>
    </container-y2>
</container-y1>

about 4 years ago · Santiago Trujillo Report
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!