Connecting Tech Pros Worldwide Help | Site Map

html DOM : unable to insertBefore a DL node.

 
LinkBack Thread Tools Search this Thread
  #1  
Old February 10th, 2006, 05:35 PM
e michael brandt
Guest
 
Posts: n/a
Default html DOM : unable to insertBefore a DL node.

I am frustrated. It appears that one can not use insertBefore to insert
an A node before a DL node. Is that really true?

I *am* able to insert before a <p id="hh"> tag, but not before a <dl
id="hh"> tag.

i am able to do a body.appendChild with no trouble.

Finally, winIE6 pops an error: 'Invalid argument' at the last snip line
below (FF1.5 fails silently):

A snip from my code:

****
var newA = document.createElement("A");

var refObj=document.getElementById("hh");

//document.body.appendChild(newA); //works fine
document.body.insertBefore(newA,refObj);// winIE6 error: 'Invalid argument'
****

Any ideas why this is happening Is it me? or is there some rule I've
not been able to find?

Thanks for any help.

P.S. Same problem if I use "div1", a div wrapper around the dl node,
instead of body node.

emichael b.

  #2  
Old February 10th, 2006, 05:45 PM
Martin Honnen
Guest
 
Posts: n/a
Default Re: html DOM : unable to insertBefore a DL node.



e michael brandt wrote:

[color=blue]
> A snip from my code:
>
> ****
> var newA = document.createElement("A");
>
> var refObj=document.getElementById("hh");
>
> //document.body.appendChild(newA); //works fine
> document.body.insertBefore(newA,refObj);// winIE6 error: 'Invalid argument'[/color]

You want/need
if (refObj != null) {
refObj.parentNode.insertBefore(newA, refObj);
}
You always need to call the DOM methods insertBefore and appendChild on
the parent node you want to append to or insert into.

--

Martin Honnen
http://JavaScript.FAQTs.com/
  #3  
Old February 10th, 2006, 06:05 PM
e michael brandt
Guest
 
Posts: n/a
Default Re: html DOM : unable to insertBefore a DL node.

wow! That works perfectly. I read every google hit I could find and
never did I see this. Thanks so much!

emichael

Martin Honnen wrote:[color=blue]
>
>
> e michael brandt wrote:
>
>[color=green]
>> A snip from my code:
>>
>> ****
>> var newA = document.createElement("A");
>>
>> var refObj=document.getElementById("hh");
>>
>> //document.body.appendChild(newA); //works fine
>> document.body.insertBefore(newA,refObj);// winIE6 error: 'Invalid
>> argument'[/color]
>
> You want/need
> if (refObj != null) {
> refObj.parentNode.insertBefore(newA, refObj);
> }
> You always need to call the DOM methods insertBefore and appendChild on
> the parent node you want to append to or insert into.
>[/color]
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.