2

i have this html code, how can i get the text which has selected="selected" option with jquery ?

   <option selected="selected" value="1">m</option>
<option value="2">n</option>
<option value="3">o</option>
<option selected="selected" value="4">p</option>
<option value="5">q</option>
<option value="6">r</option>
<option value="7">s</option>
<option selected="selected" value="8">t</option>
<option value="9">u</option>
<option value="10">v</option>

thanks

1

1 Answer 1

1

Well, you can put them in an array

var arr = $('option:selected').map(function(){ return $(this).text() }).get();
// arr[0] = 1
// arr[1] = 4
// arr[2] = 8

I suppose it's multi select.

Sign up to request clarification or add additional context in comments.

2 Comments

Bear in mind that the attribute-equals selector won't match any options selected by the user following page-load.
it is simple : var selected=$( "#myselectId option:selected" ).text();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.