Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

html DOM : unable to insertBefore a DL node.

46 views
Skip to first unread message

e michael brandt

unread,
Feb 10, 2006, 1:23:09 PM2/10/06
to
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.

Martin Honnen

unread,
Feb 10, 2006, 1:33:41 PM2/10/06
to

e michael brandt wrote:


> 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'

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/

e michael brandt

unread,
Feb 10, 2006, 1:54:17 PM2/10/06
to
wow! That works perfectly. I read every google hit I could find and
never did I see this. Thanks so much!

emichael

0 new messages