Hi Erik -
With your particular example, give this plugin a try:
jQuery.fn.sort = function() {
return this.pushStack( [].sort.apply( this, arguments ), []);
};
We've been talking about adding this for a little while now, so it may
become official:
http://jquery.com/dev/bugs/bug/255/
Using that plugin you can use your exact snippet, above. Let me know
if this helps.
--John
> I've been using jQuery for a month or so now and am really enjoying it!
>
> I haven't been able to figure out how to sort a collection of elements. I
> have something like the following:
>
> <div class="entry"><span class="foo">foo1</span><span
> class="bar">bar1</span></div
> <div class="entry"><span class="foo">foo2</span><span
> class="bar">bar2</span></div
>
> I would like to be able to do something like:
>
> $('.entry').sort(function(a, b) { return $('.foo', a).text()-$('.foo',
> b).text(); }).appendTo('#sortedStuff');
>
> Or something like that. I know javascript has a sort function, but that's
> for arrays, so I'm not sure how that will work with jQuery? Also, a google
> search for 'jquery sort' (no quotes), brings up some stuff about sorting in
> the jQuery code, but it appears old and I can't find anything about sorting
> in the latest release.
>
> Lastly, jQarray.js seems like it would do what I want, but it appears that
> site is gone (taking jXs with it, btw). It would be nice if plugins were
> cached on the jQuery site. Anybody have jQarray/jXs?
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/