darksky
darksky

Reputation: 21019

Changing <select> Options with jQuery

I've read the following post:

How to change options of <select> with jQuery?

However, my document has multiple <select>s. How can I choose to change only one of them?

Upvotes: 0

Views: 508

Answers (2)

Sam Battat
Sam Battat

Reputation: 5745

first you can assign an id to the select tags i.e

<select id="sel1">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

<select id="another-select">
    <option value="1">Option 1</option>
    <option value="2">Option 2</option>
    <option value="3">Option 3</option>
</select>

Then you change the particular SELECT tag that you need:

$('#sel1').html('<option value="1">New Option 1</option><option value="2">New Option 2</option><option value="3">New Option 3</option>');

Upvotes: 0

Niet the Dark Absol
Niet the Dark Absol

Reputation: 324620

Set an ID on it.

<select id="changeme">...</select>
....
$("#changeme")....

Upvotes: 3

Related Questions