javascript - select2 - clear all items not working when targeting by class -


i have select2 combobox, want clear out items.

if target select id, works:

$("#clearid").click(function(){   $("#list").empty(); }); 

however, if target select class, removes select dom:

$("#clearclass").click(function(){     $(".list").empty(); }); 

this can seen in following demo: http://jsfiddle.net/nvrzu/

i need able target select via class.

the dynamically added parent of select gets .list class when plugin wraps original select, you're not removing options in select, select well, you're emptying parent element.

excluding wrapper added plugin should solve problem :

$("#clearclass").click(function(){     $(".list").not('.select2-container').empty(); }); 

fiddle


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -