Kanishka Kanishka - 3 years ago 193
Javascript Question

Remove items multi select with optgroup in jquery

Is there a way to clear all option and optgroup HTML elements by using jquery?

My HTML select element is like this,

<select id="users" name="multiselect" multiple="multiple" style="width:382px;" >
<optgroup id="groupadmin" label="Group Admin"></optgroup>
<optgroup id="systemusers" label="System User"></optgroup>

Answer Source

You can use .empty()

Description: Remove all child nodes of the set of matched elements from the DOM.





As you are using multiSelect plugin, You need to use .multiSelect('refresh') method.


Updated Fiddle

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download