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

139
Views
How many repaints of the DOM will appending children in a for loop cause?

How many repaints of the DOM will appending children in a for loop cause?

I was under the impression this would cause 200. 1 for each time an element is appended, and 1 every time its textContent is updated.

But, in Jake Archibald's talk at JSConf, he seems to mention that browsers will batch this together.

for (let i = 0; i < 100; i++){ 
  const div = document.createElement('div');
  document.body.appendChild(div);
  div.textContent = 'Hello';
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Only once; see Erin Zimmer's continuation on the rendering pipeline https://youtu.be/u1kqx6AenYw

Also, you may test it with something like:

//document.body.innerHTML = '';
for (let i = 0; i < 100; i++){ 
  const div = document.createElement('div');
  document.body.appendChild(div);
  div.textContent = 'Hello';
  let x = 0;
  for(let j = 0; j < 1e7; j++){
     x += Math.sin(Math.random())
  }
}```
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!