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

198
Views
Javascript appendchild doesn't work as expected

I have the following simple code where I try to create a div inside another div using appendChild.

let div1 = document.querySelector('div')
let div2 = document.createElement('DIV')
div1.appendChild(div2)
for (let x = 0; x < 100; x++) {
  div1.textContent += "Text "
  if (x <= 30) {
    div2.textContent += 'Yes '
  }
}

console.log(div1)
console.log(div2)
<div></div>
I am not sure why this code doesn't working. The div has already been created but just not appending to the div1.

Could anyone explain me what is wrong with the appendChild? I think there is no syntax problem with appendChild

Thanks for any responds!

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!