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

  • SEARCH
  • Home
  • 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 8796047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:31:54+00:00 2026-06-13T23:31:54+00:00

Similar questions have been asked. I’m looking to clarify the best solution for a

  • 0

Similar questions have been asked. I’m looking to clarify the best solution for a specific scenario.

I want to move all the innerHTML to another element. I have:

<div class='mydiv'>
    Any HTML could be here. <span></span><div></div> etc..
</div>

And want to append/prepend/insertAfter/whatever to this div:

<div class='myotherdiv'>
    Any HTML could be here as well. <span></span><div></div> etc..
</div>

Is innerHTML += and the like the only viable solution? Or is there some way to move the whole node list from the first div and append it to the second div? I COULD grab every node individually, loop and append them in order to the second div – I do not want to do that, for performance reasons. I’m looking for some voodoo magics here, old browser need not apply, and no libraries, please.

  • 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-13T23:31:55+00:00Added an answer on June 13, 2026 at 11:31 pm

    Probably the most efficient way is to use a DocumentFragment:

    // The following assumes the existence of variables div1 and div2
    // pointing to the source and destination divs respectively
    
    var frag = document.createDocumentFragment();
    var child;
    while ( (child = div1.firstChild) ) {
        frag.appendChild(child);
    }
    
    div2.appendChild(frag);
    

    If you really wanted to avoid the while loop then you could use the extractContents() method of a DOM Range (note: not supported in IE < 9). Theoretically, it could be more efficient than the previous approach since it reduces the number of DOM calls made by script, but I haven’t benchmarked it.

    var range = document.createRange();
    range.selectNodeContents(div1);
    var frag = range.extractContents();
    div2.appendChild(frag);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Similar questions have been asked but cannot find a solution that works well. What
I know that similar questions have been asked all over the place, but I'm
Similar questions have been asked before, but I can't find the specific details I'm
I know similar questions have been asked many times. But all I can find
I know similar questions have been asked before, but I think my solution is
Similar questions have been asked on SO, but I am still looking for a
Similar questions have been asked before, but there is something I need all the
Similar questions have been asked, but none answer this specific question. Given this representative
I know similar questions have been asked but they all have different answers and
similar questions have been asked before but I cant find an exact match to

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.