Use JavaScript sort() Method
- This example show how to sort an unordered list by using array and for loop.
You will need to write your own html code to genrete ul.
here is a basic ul and sort button.
<input type='button' value='Sort' onclick='SortLang()' />
<ul>
<li>HTML</li>
<li>JavaScript</li>
<li>C #</li>
<li>VB</li>
</ul>
and here is this SortLang () function
function
SortLang() {
var languages = [];
var items = document.getElementsByTagName("li");
for (var i = 0, l = items.length; i
< l; i++) {
languages.push(items[i].innerHTML)
}
languages.sort();
for (var i = 0, l = items.length; i
< l; i++) {
items[i].innerHTML =
languages[i];
}
}
Try It