Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript/jquery remove or delete option from select

I need to delete an option from a select in certain circumstances.

Basically:

if(mystatement == true)
{
   //remove item with id 'option1' from select of id 'select1'
}

Anyone know the code for me to achieve this?

Many thanks.

like image 881
AndrewC Avatar asked Mar 11 '10 11:03

AndrewC


1 Answers

Remove by Value:

$("#select1 option[value=1]").remove();

Remove by Text:

$("#select1 option:contains(Text)").remove();
like image 119
gnarf Avatar answered Sep 21 '22 13:09

gnarf