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
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.
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.
$(this). find('[value="X"]'). remove();
$("option[value='foo']").remove();
or better (if you have few selects in the page):
$("#select_id option[value='foo']").remove();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With