Hi SO-ers,
I currently use the sort function to sort my div elements based on the count value. Here's how it's being done now: (I'm not sure if it's an efficient method or not..)
$('#list .list_item').sort(sortDescending).appendTo('#list');
function sortDescending(a, b) {
return $(a).find(".count").text() < $(b).find(".count").text() ? 1 : -1;
};
I'm thinking of adding a timestamp field and am unsure how I can extend it to support this.
I have a list of div elements with its own count and date/time/timestamp. Here's how the html code would look like:
<div id="list">
<div id="list_item_1" class="list_item">
<div class="count">5</div>
<div class="timestamp">1272217086</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis quis ipsum rutrum metus rhoncus feugiat non vel orci. Etiam sit amet nisi sit amet est convallis viverra</div>
</div>
<div id="list_item_2" class="list_item">
<div class="count">5</div>
<div class="timestamp">1272216786</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis quis ipsum rutrum metus rhoncus feugiat non vel orci. Etiam sit amet nisi sit amet est convallis viverra</div>
</div>
<div id="list_item_3" class="list_item">
<div class="count">10</div>
<div class="timestamp">1272299966</div>
<div class="text">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis quis ipsum rutrum metus rhoncus feugiat non vel orci. Etiam sit amet nisi sit amet est convallis viverra</div>
</div>
</div>
I would like to sort by count (decreasing), followed by timestamp (decreasing - newest at the top).
Any help is greatly appreciated! Thanks :)