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

Arnkrishn picture Arnkrishn · Dec 30, 2009 · Viewed 163.8k times · Source

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

Answer

Y. Shoham picture Y. Shoham · Dec 30, 2009

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

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

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