I\'m trying to take the contents of a list, that is not in alphabetical order, then by adding each item to an array, sort them into alphabetical order and insert them back i
Adjust id to className at .alphabet element to prevent duplicate ids in document.
id
className
.alphabet
document
You can use String.prototype.split() with "" as parameter, Array.prototype.sort(), .text()
String.prototype.split()
""
Array.prototype.sort()
.text()
var li = $(".alphabet"), text = li.text().split("").sort(); li.text(function(index) { return text[index] })
B C A