AndrewC AndrewC - 4 years ago 153
Javascript Question

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.

Answer Source

Edit

Since id is unique in the document no need to relate it to the parent select element. You can do simply

$("#option1").remove();
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download