Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8047221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:02:10+00:00 2026-06-05T06:02:10+00:00

If you create a DocumentFragment using document.createDocumentFragment() , append children to it, then append

  • 0

If you create a DocumentFragment using document.createDocumentFragment(), append children to it, then append the buffer to something, all the children of the buffer seem to disappear. Example:

var buffer = document.createDocumentFragment() ;

for (var i = 1; i <= 10; i++)
{
    var div = document.createElement('div');
    div.innerHTML = i;
    buffer.appendChild(div);
}

console.log( 'buffer: ' , buffer );

document.getElementById('container').appendChild(buffer);

console.log( 'buffer now: ' , buffer );

Here, in the first console.log, the buffer’s childNodes has 10 children, in the second, childNodes has 0.

Is there a way to retain the childnodes somewhere and not have them reset, in order to cache the buffer and not have to append children to it each time?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T06:02:11+00:00Added an answer on June 5, 2026 at 6:02 am

    You’ve just described the nature of a DocumentFragment. If you want to reuse the same contents, you could clone the fragment before appending it to the document each time:

    var bufferCopy = buffer.cloneNode(true);
    document.getElementById('container').appendChild(bufferCopy);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Creating a document fragment using plain Javascript is dead simple: var docFragment = document.createDocumentFragment();
I want to use document.createDocumentFragment() to create an optimized collection of HTML elements that
var oFra = document.createDocumentFragment(); // oFra.[add elements]; document.createElement(div).id=myId; oFra.getElementById(myId); //not in FF How can
Create facebook app Using a cURL to post a message from an App but
In my tests, i create some document fragment with jQuery like: el = $(<span>hello
I'm trying to create a new environment in my LaTeX document where indentation in
My goal is to remove all <[script]> nodes from a document fragment (leaving the
I was reading about document fragments and DOM reflow and wondered how document.createDocumentFragment differed
How do you use createDocumentFragment to create seven nested div elements in one hit?
Create default iPad split view based apps from template from xcode 4, then we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.