[jQuery] Re: sorting a list of elements

2009-01-16 Thread Dave Methvin
Making an array works, but you can also apply the array sort method directly to the jQuery object since it's array-like (has a length and [0]...[length-1] elements. Array.prototype.sort.call( $('#ops-memb option'), function(a,b) { return $(a).text() > $(b).text() ? 1 : -1; } ).a

[jQuery] Re: sorting a list of elements

2009-01-16 Thread mtz
Great ! Thank you very much. On Jan 16, 2:54 pm, jac wrote: > here is an example of a solution to what it sounded like you were > asking about. > > http://jsbin.com/aquja > > just add "/edit/" to the end of the url to see all of the source. You > can even double click and make modifications. Ho

[jQuery] Re: sorting a list of elements

2009-01-16 Thread jac
here is an example of a solution to what it sounded like you were asking about. http://jsbin.com/aquja just add "/edit/" to the end of the url to see all of the source. You can even double click and make modifications. Hope this helps. On Jan 16, 12:44 pm, mtz wrote: > Thanks. > I can make the

[jQuery] Re: sorting a list of elements

2009-01-16 Thread mtz
Yeah - I think this is getting too complicated. I actually am only inserting one item at a time. Rather than sort, I think I only need to go through the existing items which are already in alphabetical order, and find where to insert the new one. On Jan 16, 1:58 pm, brian wrote: > You'll need to

[jQuery] Re: sorting a list of elements

2009-01-16 Thread brian
You'll need to save the output into a variable, then loop through that to create new options and replace the existing ones. var new_opts = $.makeArray($('#ops-memb option')).sort(... There's probably a neat jQuery way to do all of this compactly. On Fri, Jan 16, 2009 at 1:44 PM, mtz wrote: > >

[jQuery] Re: sorting a list of elements

2009-01-16 Thread mtz
Thanks. I can make the array now and it legitimately sorts. However, I can't see an easy way to get the values in the array back into the A name format again, so I can put teh HTML into the select . On Jan 16, 1:33 pm, brian wrote: > http://docs.jquery.com/Utilities/jQuery.makeArray#obj > -- sni

[jQuery] Re: sorting a list of elements

2009-01-16 Thread brian
http://docs.jquery.com/Utilities/jQuery.makeArray#obj -- snip -- jQuery.makeArray( obj ) Turns anything into a true array. -- snip -- On Fri, Jan 16, 2009 at 1:25 PM, Kean wrote: > > Only true arrays will inherit the sort method. > > On Jan 16, 10:10 am, brian wrote: >> Maybe use makeArray() fi

[jQuery] Re: sorting a list of elements

2009-01-16 Thread Kean
Only true arrays will inherit the sort method. On Jan 16, 10:10 am, brian wrote: > Maybe use makeArray() first. Something like: > > $.makeArray($('#ops-memb option')).sort(... > > On Fri, Jan 16, 2009 at 11:04 AM, mtz wrote: > > > I have a select list into which I place new option elements, and

[jQuery] Re: sorting a list of elements

2009-01-16 Thread brian
Maybe use makeArray() first. Something like: $.makeArray($('#ops-memb option')).sort(... On Fri, Jan 16, 2009 at 11:04 AM, mtz wrote: > > I have a select list into which I place new option elements, and I > want to show them in sorted order. I've searched around and tried some > approaches, but