I\'m using jQuery select2 multi select dropdown. I need to select all options in a dropdown from code. Basically there is a Select All checkbox on which this functionality h
$(document).ready(function() {
$("#my-select").select2();
});
function selectAll() {
$("#my-select > option").prop("selected", true);
$("#my-select").trigger("change");
}
function deselectAll() {
$("#my-select > option").prop("selected", false);
$("#my-select").trigger("change");
}
.button-container {
margin-bottom: 10px;
}
#my-select {
width: 200px;
}
This is the simplest way
function selectAll() {
$("#my-select > option").prop("selected", true);
$("#my-select").trigger("change");
}