JQuery get text with $ .each from multiple select list

I am trying to get the text of some selected options from a select list using the jQuery.each function.

I select all the selected options as follows: $('#IdOfSelect option:selected')
This works fine.

If I iterate over this jQuery object, I always get an error is value.text()not a function when I try to get the text of my only option.

You can see this behavior here: http://jsfiddle.net/z2nbP/

In the Firebug-Console, the element is displayed as <option value="10">instead of the expected one [option](if it is a DOM object).

How can I iterate over these selected parameters and although get texts there?

+5
source share
4 answers

You need the following:

$(value).text()

since the parameter valuepassed to the callback is an internal DOM element that does not have a method .text()defined on it.

Here's an updated demo .

+11
source

Try the following: http://jsfiddle.net/9arYE/

+1
source

The value is not a jquery object, you should make it as a jquery object this way -

$(value).text();
0
source

Try the following:

$ ('# result'). append ($ (this) .val () + '
');

0
source

All Articles