Reputation: 27
I want to REMOVE all items in the chosen.js multi select drop-down, How can I do this? I tried using..
var ddlSitesID = $("#SelectedSites option").length
if (ddlSitesID) {
for (i = 0; i != ddlSitesID; i++) {
$("#SelectedSites option").remove(i);
}
}
But it does not work, please help.
Upvotes: 0
Views: 2256
Reputation: 27
I found the solution,
First run this..
var ddlSitesID = $("#SelectedSites option").length
if (ddlSitesID) {
for (i = 0; i != ddlSitesID; i++) {
$("#SelectedSites option").remove(i);
}
}
then run this after it
$('#SelectedSites').trigger('chosen:updated');
Upvotes: 0
Reputation: 2455
Try this: jsfiddle.net/bharatsing/j9yuL/131/
//To clear selection
$('#SelectedSites option').prop('selected', false).trigger('chosen:updated');
//Remove all items
$('#SelectedSites').html("");
$("#SelectedSites").chosen().trigger('chosen:updated');
Upvotes: 2
Reputation: 412
You can do this with two way
-First way:
$('#SelectedSites').html('');
-Second way:
$('#SelectedSites').find('option').remove().end();
Upvotes: 1