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

java - Cast from Object to List<String>: CastClassException -

How to set a border for android Imageview in Longpress? -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -