I'm trying to get the text of some selected options from a select list with the jQuery.each function.
I select all selected options like this: $('#IdOfSelect option:selected')
This works just fine.
If I iterate over this jQuery-object I always get the error value.text()
is not a function when I try to get the text of my single option.
You can see this behaviour here: http://jsfiddle.net/z2nbP/
In the Firebug-Console the item shows as <option value="10">
instead of my expected [option]
(if it's a DOM-object).
How is it possible to iterate over those selected options and although get there texts?
You need this:
$(value).text()
because the value
parameter passed to the callback is the native DOM element which doesn't have the .text()
method defined on it.
Here's the updated demo.
Try this: http://jsfiddle.net/9arYE/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With