Getting jQuery sort code meant for <ul> to work for tables
<p>How I would I get the jQuery code saved here: <a href="http://jsfiddle.net/stodolaj/De8Ku/" rel="nofollow">http://jsfiddle.net/stodolaj/De8Ku/</a> to work for tables? I have one saved at <a href="http://jsfiddle.net/uJmJ7/" rel="nofollow">http://jsfiddle.net/uJmJ7/</a> that I want to apply it to when the user clicks on the table header I would like the table rows to be sorted in alphabetical or numerical order. Here is the abovementioned code:</p>

<pre><code>function sortUnorderedList(ul, sortDescending) {
    if (typeof ul == "string") {
        ul = document.getElementById(ul);
    }
    var lis = ul.getElementsByTagName("LI");
    var vals = [];
    for (var i = 0, l = lis.length; i &lt; l; i++) {
        vals.push(lis[i].innerHTML);
    }
    vals.sort();
    if (sortDescending) {
        vals.reverse();
    }
    for (var i = 0, l = lis.length; i &lt; l; i++) {
        lis[i].innerHTML = vals[i];
    }
}

window.onload = function () {
    var desc = false;
    document.getElementById("test").onclick = function () {
        sortUnorderedList("list", desc);
        desc = !desc;
        return false;
    }
}
</code></pre>
