Even easier than that:
jQuery.fn.sort = function() {
return this.pushStack( jQuery.makeArray( [].sort.apply( this,
arguments )) );
};
See here: http://dev.jquery.com/ticket/255
Looks like I'm still about the only person that actually uses this.
--Erik
On 3/26/07, Luke Lutman <[EMAIL PROTECTED]> wrote:
> I'd guess it's because arguments isn't really an array (it has a length
> property, but none of
> Array's methods).
>
> Something like this might do the trick:
>
> jQuery.fn.sort = function() {
> for(var i = 0, args = []; i < arguments.length; i++)
> args.push(i);
> return this.pushStack( [].sort.apply( this, args ), []);
> };
>
> Luke
>
>
> Bruce McKenzie wrote:
> > There was a thread on this list in October which indicates (if I read it
> > right) that I ought to be able to rearrange some paragraphs as follows:
> >
> > <script type="text/javascript">
> >
> > $(function(){
> >
> > jQuery.fn.sort = function() {
> > return this.pushStack( [].sort.apply( this, arguments ), []);
> > };
> >
> > $("p.items").sort(function(a,b){
> > return a.innerHTML > b.innerHTML ? 1 : -1;
> >
> > }).appendTo("#Foo");
> >
> > });
> > </script></head>
> > <body>
> >
> > <div id='Foo'>
> > <p class='items'>C</p>
> > <p class='items'>B</p>
> > <p class='items'>A</p>
> > </div>
> >
> > </body>
> > </html>
> >
> > But this error results:
> > error: second argument to Function.prototype.apply must be an array
> >
> > Is it me -- or does the sort function need to be adjusted for jQuery
> > 1.1.1 (and how would a person do that :-) ?
> >
>
>
> --
> zinc Roe Design
> www.zincroe.com
> (647) 477-6016
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/