By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,460 Members | 1,151 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,460 IT Pros & Developers. It's quick & easy.

Append Child working in Mozilla but not in IE.

dmjpro
100+
P: 2,476
Have a look at my code fragment...

Expand|Select|Wrap|Line Numbers
  1. var parent_UL_ref = parent.document.getElementById(..);
  2. var child_LI_ref = document.createElement('LI');
  3. parent_UL_ref.appendChild(child_LI_ref); //it's not working
  4.  
Actually my question is if create an element using document.createElement, can it be added into any another document. I think that's what happening here ... ;)
May 6 '09 #1
Share this Question
Share on Google+
5 Replies


Ciary
Expert 100+
P: 247
normally there shouldnt be a problem with it. i'm doing the same in my current project. only there i create divs containing dynamically created paragraphs.

another option:
Expand|Select|Wrap|Line Numbers
  1. var parent_UL_ref = parent.document.getElementById(..);
  2. var parent_UL_ref .style.innerHTML += "<li>item</li>
  3.  
May 6 '09 #2

acoder
Expert Mod 15k+
P: 16,027
You need to use imporNode.
May 6 '09 #3

dmjpro
100+
P: 2,476
@Ciary
Here you directly setting the innerHTML. I am talking about the document.createElement ;)
May 6 '09 #4

dmjpro
100+
P: 2,476
Well i got the solution...

I have a opener window and a pop-up window, and there code given below.

Expand|Select|Wrap|Line Numbers
  1. //onload function
  2. function openPopUp(){
  3.  window.open(......);
  4. }
  5.  
Expand|Select|Wrap|Line Numbers
  1. //add-list handler
  2. function addList(){
  3.  var parent_UL_ref = opener.document.getElementById(..) ; //get the opener UL reference
  4.  var child_LI_ref = document.createElement('LI');
  5.  parent_UL_ref.appendChild(child_LI_ref); //here it says no such interface supported
  6. }
  7.  
Up to this the whole code works in Mozilla but not in IE.

if i change the code like this ....
Expand|Select|Wrap|Line Numbers
  1. var child_LI_ref = opener.document.createElement('LI');
  2.  
Then it works in both ;)
May 6 '09 #5

acoder
Expert Mod 15k+
P: 16,027
If you're going to stick to the same document, then it will work. If not, you should be using importNode, but unfortunately, it's not been implemented in IE though you can find versions online.
May 6 '09 #6

Post your reply

Sign in to post your reply or Sign up for a free account.