How to order a <ul> element using jQuery

<ul> <li>cloud</li> <li>sun</li> <li>rain</li> <li>snow</li> </ul var items = $('.to_order li').get(); items.sort(function(a,b){ var keyA = $(a).text(); var keyB = $(b).text(); if (keyA < keyB) return -1; if (keyA > keyB) return 1; return 0; }); var ul = $('.to_order'); $.each(items, function(i, li){ ul.append(li); });

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.