Home > JavaScript, jQuery > Add sorting ability to jQuery

Add sorting ability to jQuery

October 28th, 2008

Self-explanatory :)

jQuery.fn.sort = function() {
return this.pushStack( jQuery.makeArray( [].sort.apply( this, arguments ) ) );
};

See here for an explanation on custom sorting in JavaScript.

Share this Article:
  • Print
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Add to favorites
  • email
  • FriendFeed
  • LinkedIn
  • Netvibes
  • Reddit
  • Slashdot
  • StumbleUpon
  • Tumblr
  • Twitter

booshtukka JavaScript, jQuery

  1. Andy B
    | #1

    Ninja! And I thought I wrote terse code…

    Just wondering whether you need the literal array in there…

    Array.prototype.sort? I’m rusty so couldn’t quite follow the scoping of the nested this keyword.

  2. booshtukka
    | #2

    It’s a while, but I seem to recall it wouldn’t work without the literal array. Feel free to play?

  1. No trackbacks yet.