admin管理员组文章数量:1393086
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>
</select>
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>
</select>
Share
Improve this question
edited Jun 26, 2014 at 12:08
Ja͢ck
174k39 gold badges266 silver badges314 bronze badges
asked Jun 26, 2014 at 11:47
KanishkaKanishka
232 silver badges7 bronze badges
2
- Yes there is; have you tried anything? – Ja͢ck Commented Jun 26, 2014 at 11:58
- I have tried following ways, $('#users').empty(); $('#users').find('optgroup,option').remove(); $('#users').html($('#users').html().replace('selected','')); – Kanishka Commented Jun 26, 2014 at 12:06
3 Answers
Reset to default 6You can use .empty()
Description: Remove all child nodes of the set of matched elements from the DOM.
Code
$('#users').empty()
Fiddle
EDIT
As you are using multiSelect plugin, You need to use .multiSelect('refresh')
method.
$('#users').empty().multiSelect('refresh');
Updated Fiddle
Try this code
$('#users').find('optgroup,option').remove();
Use the following code :
$('#users').children().remove();
This will work irrespective of whether an optgroup is present or not
本文标签: javascriptRemove items multi select with optgroup in jqueryStack Overflow
版权声明:本文标题:javascript - Remove items multi select with optgroup in jquery - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744757197a2623534.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论