简体   繁体   中英

Remove selected value from dropdown using javascript

I have 3 drop down field with same name. I need to remove selected option from second drop down field. I tried with this:

$(".salaryAdd option:selected").remove();   

You can do it by selecting the second select with eq and clearing it's value using val like this:

 $(".salaryAdd:eq(1)").val(''); //---------------^ eq is zero index based // or $(".salaryAdd").eq(1).val('');
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <select class="salaryAdd"> <option selected>hi</option> </select> <select class="salaryAdd"> <option selected>hi</option> </select> <select class="salaryAdd"> <option selected>hi</option> </select>

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