Cheok Yan Cheng Cheok Yan Cheng - 3 months ago 28
Javascript Question

How to use JQuery to select the nth option

I have the following HTML

<select onchange="this.form.submit()" name="name">
<option value="9995101E01#17201044055PM">9995101E01#17201044055PM</option>
<option value="GRR-Example">GRR-Example</option>
<option value="admin">admin</option>
<option value="123w">123w</option>
</select>


May I know how I can use JQuery to option with value "admin"?

Thanks.

Answer
$('select[name=name] option:eq(2)').attr('selected', 'selected');

Demo.

Comments