Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use jQuery select an option?

<select>
            <option value="0" id="n">n</option>
            <option value="1" id="m">m</option>
</select>

In jQuery, how do I make the option 'selected' for id=m?

like image 942
TIMEX Avatar asked Feb 24 '10 04:02

TIMEX


1 Answers

Set an id on the select element instead:

<select id="TheDropDown">
   <option value="0">n</option>
   <option value="1">m</option>
</select>

Then use the val function:

$('#TheDropDown').val('1');
like image 181
Guffa Avatar answered Oct 12 '22 11:10

Guffa