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 <option id='123''>A name</option> format again, so I can put teh HTML into the select .
On Jan 16, 1:33 pm, brian <bally.z...@gmail.com> wrote: > 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 <shenan...@gmail.com> wrote: > > > Only true arrays will inherit the sort method. > > > On Jan 16, 10:10 am, brian <bally.z...@gmail.com> wrote: > >> Maybe use makeArray() first. Something like: > > >> $.makeArray($('#ops-memb option')).sort(... > > >> On Fri, Jan 16, 2009 at 11:04 AM, mtz <tracey.zellm...@gmail.com> 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 not successful yet. > > >> > Here is an example. > >> > It may not be the best use of jQuery, but at least I understand it. > >> > The select element has id ops-memb > >> > I get the current content, then add another option item. > > >> > var members = $('#ops-memb').html() + "<option id='507'>Another Item</ > >> > option>"; > >> > $'#ops-memb').html(members); > > >> > This works. > >> > Now I try to sort > > >> > $('#ops-memb option').sort(function(a,b) { > >> > return $(a).text() > $(b).text() ? 1 : -1; > >> > }); > > >> > I get an error message that $('#ops-memb').sort is not a function > > >> > Could someone help me understand what I am doing wrong and how to get > >> > this to work correctly? > > >> > Thanks.