View Single Post
Old 04-09-2009, 08:43 AM   PM User | #2
Iszak
Regular Coder

 
Iszak's Avatar
 
Join Date: Jun 2007
Location: Perth, Western Australia
Posts: 332
Thanks: 2
Thanked 58 Times in 57 Posts
Iszak is an unknown quantity at this point
Okay, well I made something although it's not exactly what you wanted, it's similar and with some editing I'm sure you can acheive what you want. Although the way I've done this I believe isn't the best and effecient way, it gets the job done. Sorry I couldn't help anymore.

HTML
Code:
<ul id="list">
  <li value="100">100</li>
  <li value="32">32</li>
  <li value="68">68</li>
  <li value="5">5</li>
</ul>

<input id="submit" type="submit" value="Add List Item">
<input id="value" type="text" value="20">
JavaScript
Code:
function sortDesc(a, b)
{
  return (b - a);
}

$('#submit').click(function(){
  var value = $('#value').val();

  $('#list').append('<li value="'+value+'">'+value+'</li>\n');

  list = new Array();

  jQuery.each($('#list > li'), function(){
    list = list.concat($(this).attr('value'))
  });

  list.sort(sortDesc);

  $('#list').children().remove();

  jQuery.each(list, function(){
    $('#list').append('<li value="'+this+'">'+this+'</li>\n');
  });
});
Should be noted I don't believe the value attribute is valid.. so maybe look into something else?

Preview: http://pastebin.me/49dda6757604b
Iszak is offline   Reply With Quote