Sorting a listview using jQuery?
<p>Here the code is only sorting the li items in ascending order.How to sort in both ascending and descending order by using this code <a href="http://stackoverflow.com/questions/1496033/sorting-li-tags">Sorting &lt;li&gt; tags</a></p>

<pre><code> function sort(list, key) {
         $($(list).get().reverse()).each(function (outer) {
             var sorting = this;
             $($(list).get().reverse()).each(function (inner) {
                 if ($(key, this).text().localeCompare($(key, sorting).text()) &gt; 0) {
                     this.parentNode.insertBefore(sorting.parentNode.removeChild(sorting), this);
                 }
             });
         });
     }
</code></pre>

<p>and</p>

<pre><code>window.onload = function () {
         var desc = false;
         document.getElementById("stCodeDSC").onclick = function () {
             //             sortUnorderedList("list3", desc);

             sort('ul.conn1&gt;li', 'td.code1');
             desc = !desc;
             return false;
         }
</code></pre>

<p>Any suggestion?</p>

<p>EDIT: If i give <code>&lt;0</code> then it is sorting in descending order..</p>

<p>EDIT2:</p>

<pre><code>$(document).ready(function() {
         var desc = false;
         document.getElementById("stCodeDSC").onclick = function () {
             //             sortUnorderedList("list3", desc);

             sort('ul.conn&gt;li', 'td.code');

             desc = !desc;
             return false;
         }
         document.getElementById("stNameDSC").onclick = function () {
             //             sortUnorderedList("list3", desc);

             sort('ul.conn&gt;li', 'td.name');
             desc = !desc;
             return false;
         }
     });
</code></pre>
