Source Code:
(back to article)
Submit
Result:
Report an issue
<!DOCTYPE html> <html> <head> <title>Batching DOM Changes</title> </head> <body> <div id="container"></div> <script> const container = document.getElementById('container'); const fragment = document.createDocumentFragment(); for (let i = 0; i < 40; i++) { const div = document.createElement('div'); div.textContent = `Item ${i}`; fragment.appendChild(div); } container.appendChild(fragment); // Batch update </script> </body> </html>