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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:00:25+00:00 2026-05-26T10:00:25+00:00

Im having a really weird IE problem that I can’t figure out what the

  • 0

Im having a really weird IE problem that I can’t figure out what the root cause is. I’m hoping to get an explanation as to what internally is going wrong. I can append a dynamically created element to another once, but any subsequent attempts to append the node removes any children appended to it.

I have a function create a wrapper div, and then appends a child ‘p’ with some text attached to it. Function essentially reads like this:

function buildElement(text){
  var node,p,doc = document;
  node = doc.createElement('div');
  node.setAttribute('class','node-wrapper');

  p = doc.createElement('p');
  p.appendChild(doc.createTextNode(text));

  node.appendChild(p);
  return node;
}

It’s pretty straight forward. This builds an element that contains the text that you pass into it. Heres a scaled down version of what I’m trying to do, and comments to describe what’s happening in IE:

// create a parent wrapper element
var wrapper = document.createElement('div');
wrapper.setAttribute('class','parent-wrapper');

var childNode = buildElement('This is a sample');

// This will append a child node with all of its children, 
// everything works as expected - ex:
// <div class="parent-wrapper">
//   <div class="node-wrapper">
//     <p>This is a sample</p>
//   </div>
// </div>
wrapper.appendChild(childNode);

// empty the parent wrapper
wrapper.innerHTML = '';

// re-append the childNode element to the parent wrapper
// in IE, this step will fill the parent node with just the node-wrapper element
// with the removed child node(s) - ex:
// <div class="parent-wrapper">
//   <div class="node-wrapper" />
// </div>
wrapper.appendChild(childNode);

What you’ll see if you run this, is that the first wrapper.appendChild(childNode) works great and as expected. But the second attempt to append the child node will result in the childNode’s children being removed from the childNode. (ex: the ‘p’ is gone.);
You can see a working example of this here:
http://jsfiddle.net/jiggliemon/52ZPR/

What’s weird is that you can avoid the child-node removal by not appending the childNode, but appending a Clone of the child node wrapper.appendChild(childNode.cloneNode(true)).
You can see a working example of this here:
http://jsfiddle.net/jiggliemon/52ZPR/3/

Here is a more elaborate example:
http://jsfiddle.net/jiggliemon/bcSpQ/

  • 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-26T10:00:26+00:00Added an answer on May 26, 2026 at 10:00 am

    wrapper.innerHTML = ''

    seems to damage your inner nodes. Don’t use it. The correct technique is

    for (var i = 0, len = wrapper.childNodes; i < len; i++) {
      wrapper.removeChild(wrapper.childNodes[i]);
    }
    

    This should fix your bug.

    However other then saying innerHTML is bad! I can’t explain your bug.

    The HTML5 specification says :

    Remove the child nodes of the node whose innerHTML attribute is being set, firing appropriate mutation events.

    So it really should not be damaging childNode

    As a side-note:

    p.textContent = text;

    is the “same” as

    p.appendChild(doc.createTextNode(text));

    As a further aside the idea that

    x.innerHTML = ''

    is a fast way to empty x is a lie.

    Benchmark

    Please use a while loop over the firstChild or set .textContent = ''

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

Sidebar

Related Questions

I'm currently having a really weird issue and I can't seem to figure out
This is a really weird problem that I have been having. When I download
Having a really aggravating problem using Managed Metadata in SP2010 where I can get
I am having a really weird problem because i get completely different results between
Really weird problem. I have a tableView that pulls data out of a Core
I'm really having a problem finding out how to fix this. I cannot seem
I am having a really really weird problem with visual studio 2008 and the
I am having a weird problem here, and I am really stuck, need to
I am having a weird problem with a small restlet service that I am
I am having really weird problem: Fatal error: Allowed memory size of 134217728 bytes

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.