JavaScript arrays support a simple sort() method for this task. This
will give you a lexicographically (dictionary) sort from A-Z.
$(function(){
arrStudents = new Array();
$(".student").each(function(i){
arrStudents[i] = $(this).text();
});
arrStudents = arrStudents.sort();
$("#classList").html(""); // clear out your previous records
for (i = 0; i < arrStudents.length; i++) {
$("#classList").append("<div class='student'>" + arrStudents[i]
+ "</div>");
}
});
You can also use an XML file, and then use AJAX to grab it and build
out your HTML. Just another way of doing it I guess.
On Apr 6, 6:14 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> Hi,
>
> I have a DIV (id = "classList") witih many smaller DIVs, each of class
> "student". The smaller DIV only contains text. If I want to add a
> new student DIV to the list, but add it in alphabetical order, is
> there a simple, tried and true jQuery way of doing this?
>
> Thanks, - Dave