Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery to remove an option from drop down list, given option's text/value

I have a drop down list and would like to remove an option from it, given the text/value of that particular option. Is it possible using jQuery? Just like 'append' which adds an option to the drop down list, is there a function to remove an option?

I tried searching for it but all I got were examples where the entire set of options in the drop down list are removed, which is not what I seek.

cheers

like image 206
Arnkrishn Avatar asked Dec 30 '09 20:12

Arnkrishn


People also ask

How do I disable a specific value in a dropdown?

In this post, I will show you how you can disable specific items of the DropDown/ComboBox/Select element using jQuery. To disable any item, just need to add attribute "disabled" with value "disabled" to the list item.

How do I remove a dropdown option?

If, instead of deleting it, you decide you want to change the options in your drop-down list, see Add or remove items from a drop-down list. Select the cells with the drop-down list. Click Data >Data Validation. On the Settings tab, click Clear All.

How do I remove dynamically selected options in jQuery?

$(this). find('[value="X"]'). remove();


1 Answers

$("option[value='foo']").remove();

or better (if you have few selects in the page):

$("#select_id option[value='foo']").remove();

like image 85
Yaakov Shoham Avatar answered Sep 23 '22 17:09

Yaakov Shoham