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 6648427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:39:14+00:00 2026-05-26T00:39:14+00:00

Suppose I have a partial dom tree with a parent node and a set

  • 0

Suppose I have a partial dom tree with a parent node and a set of children.

How can I interject a DIV between them?

I am starting with

parent --+--> child[0]
         |--> child[1]
         |--> child[2]

..and I want to end with

parent ---> newdiv ---+--> child[0]
                      |--> child[1]
                      |--> child[2]

How can I do this?

I need the converse of replaceChild() . Is there something like replaceParent() ?

I suppose I could clone all the child nodes, and then insert them as children in the new node. but… does that retain all the element ids?


EDIT – I didn’t tag this with jQuery, or any framework, but maybe I should have been explicit about it. This is not a jQuery question. I want to do this in javascript + DHTML. No extra or outside framework.

  • 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-05-26T00:39:14+00:00Added an answer on May 26, 2026 at 12:39 am

    You can just move elements around by appending them to a new parent. In plain javascript:

    var newDiv = document.createElement("div");
    
    while(parent.hasChildNodes())
        newDiv.appendChild(parent.firstChild);
    
    parent.appendChild(newDiv);
    

    From the documentation of W3C about appendChild:

    Adds the node newChild to the end of the list of children of this node. If the newChild is already in the tree, it is first removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a partial class in my application. Let's say I have one
Suppose that I have this partial view: Your name is <strong>@firstName @lastName</strong> which is
i have a question regarding partial page loading with AJAX. Suppose that an user
I have a large tree that grows as my algorithm progresses. Each node contains
Suppose I have ViewModel like public class AnotherViewModel { public string Name { get;
I'm having a problem with accessing my buttons separately using jquery. Suppose I have
I am using multiple partial views on my View. on the left-hand side. I
I think I couldnt do this thing, but I try to ask (maybe :)).
I'm using Rails 3.1.0rc4 and client_side_validations 3.1.0. Everything works perfectly so long as the

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.