Add sorting ability to jQuery

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.

2 thoughts on “Add sorting ability to jQuery

  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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>