Bug Tracker

Opened 16 years ago

Closed 15 years ago

#1430 closed enhancement (invalid)

get() issue

Reported by: scubstev834 Owned by:
Priority: minor Milestone: 1.2.2
Component: core Version: 1.2.1
Keywords: get() option:selected Cc:
Blocked by: Blocking:


When using a multi select (i.e. <select multiple=multiple>), you can easily grab all the currently selected options using $("#id option:selected").

However, it is hard to write a simple and universal handler as the get() could return an array OR just the single element. It would be much more intuitive and easier to handle if whenever a get() was called, you were returned an array, regardless of the number of elements returned. If the user is grabbing but one element, they could use the get(0).


I have written a few simple wrappers to handle this by either using the $.merge function and an anonymous array or using the $.map function to only grab the values of the selected options. For example:

var items = $.merge( new Array(), $( "#id option:selected" ).get() );


var vals =


$( "#id option:selected" ).get(),

function( i ) {

return i.value;



Change History (1)

comment:1 Changed 15 years ago by john

Milestone: 1.2.2
Resolution: invalid
Status: newclosed

.get() always returns an array. It only returns a single element if you do .get(Index).

Note: See TracTickets for help on using tickets.