select2 select all option code example
Example 1: jquery select2 multiple select all
$("#checkbox").click(function(){
if($("#checkbox").is(':checked') ){
$("select > option").prop("selected","selected");
}else{
$("select > option").removeAttr("selected");
}
});
Example 2: select 2 multiselect
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/select2.min.js"></script>
$(document).ready(function() {
$('.js-example-basic-single').select2();
});
Example 3: select2 .select2-results .select2-highlighted
$(document).ready(function() {
$("#menuOption1").select2({dropdownParent: "#menuOption1-container"});
$("#menuOption2").select2({dropdownParent: "#menuOption2-container"});
});
Example 4: select2 .select2-results .select2-highlighted
#menuOption1-container .select2-results__option--highlighted {
background-color: #50831F !important;
}
#menuOption2-container .select2-results__option--highlighted {
background-color: #28915F !important;
}