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
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
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
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
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:
>
>
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
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
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
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
9 matches
Mail list logo