I recently needed to sort div elements in the DOM by a timestamp in child divs. After searching for a while and finding no jQuery style solution, I figured out an easy way to do it, the jQuery way. Here is the code:
// Sort by timestamp.
$("#timeclock_edit").prepend($("#timeclock_edit div.element").get().sort(function(a, b){
return $(a).find(".timestamp").text() - $(b).find(".timestamp").text();
}));
The code grabs an array of DOM elements, sorts it by comparing the text in the timestamp element, then prepends that to the parent div. The way this is coded is not very flexible, but it could be expanded easily.
Read 0 Comments... >>



Articles


CSS form design has been plaguing me for a while now in the 