[thelist] sorting an <ol> using the dom

Bill Lovett bill at ilovett.com
Fri Mar 1 09:17:34 CST 2002


I've seen some nifty examples of using dom methods to sort the cells
in a table, and I'm wondering if the same thing can be done with an
ordered list. Let's say I'm working with something like this:

<ol id="foo">
    <li><a href="www.google.com">Google</a><li>
    <li><a href="www.yahoo.com">Yahoo</a></li>
    <li><a href="www.altavista.com">AltaVista</a></li>
</ol>

My goal is to alphabetize the list. I know that if I do:

document.getElementById('foo').childNodes[i].innerText

I can extract the text of each <li>, and from there, do the sort. What I
can't figure out is how to update the page with that new order. Anyone
have any ideas?

-bill



More information about the thelist mailing list