Skip to main content

Bug Tracker

Side navigation

#1430 closed enhancement (invalid)

Opened July 27, 2007 06:28PM UTC

Closed December 11, 2007 05:03PM UTC

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:
Description

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).

Thoughts?

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() );

or

var vals =

$.map(

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

function( i ) {

return i.value;

}

);

Attachments (0)
Change History (1)

Changed December 11, 2007 05:03PM UTC by john comment:1

milestone: → 1.2.2
resolution: → invalid
status: newclosed
version: 1.1.21.2.1

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