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.