<select>
<option>test</option>
<option>test1</option>
</select>
In fact I'm going to retrieve the innertext of <option>
,but these two jobs are similar.
<select>
<option>test</option>
<option>test1</option>
</select>
In fact I'm going to retrieve the innertext of <option>
,but these two jobs are similar.
$("select option").each(function() {
$(this).text(); //do something with this text
});
or if you want a concatenated string of all options then its simply
$("select option").text();
if you want values - as in value attribute of option (<option value="x">text</option>
) then replace the text()
function in the code above with val()
var opt_vals = [];
$( 'select option' ).each( function() {
opt_vals.push( ( $this ).text() );
}
With the HTML you provided, I'd just use this:
var opt_vals = $('select').text().trim().split('\n');