[thelist] document.createElement?
Peter-Paul Koch
gassinaumasis at hotmail.com
Wed Mar 26 08:11:31 CST 2003
>but, I get an error that the node (presumably c) is not found.
>
>Any ideas?
>
>sample HTML:
><ul id="contentsUL">
> <li>
> <ul>
> <li></li>
> </ul>
> </li>
> <li>
> <ul>
> <li></li>
> </ul>
> </li>
></ul>
>
>sample ECMAScript:
>var a=document.getElementById('contentsUL');
>var b=a.getElementsByTagName('ul');
>for(d=0;b[d];d++){
> var c=document.createElement('a');
>alert(c);
> a.insertBefore(c,b[d]);
>}
a is not the parent of c. There's a LI element in between. So the browser
tries to find c as a child node of a and fails.
Solution:
b[d].parentNode.insertBefore(c,b[d]);
--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
W3C DOM Compatibility Table, expanded & updated
http://www.xs4all.nl/~ppk/js/index.html?version5.html
--------------------------------------------------
_________________________________________________________________
The new MSN 8: smart spam protection and 2 months FREE*
http://join.msn.com/?page=features/junkmail
More information about the thelist
mailing list