[thelist] TOC using DOM?

Kasimir K evolt at kasimir-k.fi
Thu Jun 24 05:55:29 CDT 2004


>             newel = document.createElement("a name=\"" + ih + "\"");

I'm not sure if it is this, but I'd do:

newel = document.createElement("a");
newel.name = ih;

and then also:

newel.id = "toc" + i;

>             elem.appendChild(newel);
>             toc += "<li><a href=\"#" + ih + "\">" + ih + "</a>";

and here I'd:

toclbl = document.createTextNode(ih);
toca = document.createElement("a");
tocli = document.createElement("li");
toca.href = "#toc" + i;
toca.appendChild(toclbl);
tocli.appendChild(toca);
toc.appendChild(tocli);

// so this means that earlier there is
// toc = document.createElement("ul");

>             alert(newel.outerHTML);
>             alert(newel.innerHTML);
>         }
>     }
>     toc = "<ul>" + toc + "</ul>";

so the above line is not needed

>     var newel = document.createElement("DIV");
>     newel.innerHTML = toc;

and here too instead of using innerHTML I'd use:
newel.appendChild(toc);

>     document.body.appendChild(newel);
> }
> </script>
> 
> The problem is that although the <a name=xxx> elements are created, they
> don't receive events targetted 

I'm not sure if my suggestions will help with that, but I think they are 
at least cleaner :-)


.k



More information about the thelist mailing list