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

264
Views
Move all li items in a ul to a separate ul

Trying to move all list items in .origin ul to .target ul with vanilla javascript.

<div id="container">
  <span>Origin</span>
  <ul class="origin">
    <li class="level-top li-item">Origin entry 1</li>
    <li class="level-top li-item">Origin entry 2</li>
    <li class="level-top li-item">Origin entry 3</li>
  </ul>
  <br>
  <span>Target</span>
  <ul class="target">
  </ul>
</div>
var origin = document.querySelector('.origin');
document.querySelector(".target").append(origin);

This moves them however, it puts the entire origin ul into the target ul. Should I be iterating through the list items?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Shornt and simple solution would be

const t = document.querySelector(".target")
t.innerHTML += o.innerHTML
o.innerHTML = ""
about 4 years ago · Juan Pablo Isaza Report

0

Just append origin's children to target, like this:

const origin = document.querySelector('.origin');
const target = document.querySelector('.target');
target.append(...origin.childNodes);

or you can do it in one line like this:

document.querySelector('.target').append(...document.querySelector('.origin').childNodes)
about 4 years ago · Juan Pablo Isaza 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!