简体   繁体   中英

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?

Set an ID on it.

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

first you can assign an id to the select tags ie

<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>');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM