Skip to content

Instantly share code, notes, and snippets.

@lyonsun
Created October 28, 2015 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lyonsun/8ed7d542f7ccd69312cd to your computer and use it in GitHub Desktop.
Save lyonsun/8ed7d542f7ccd69312cd to your computer and use it in GitHub Desktop.
add a checkbox input and use this code to select or unselect all.
// credits: http://jsfiddle.net/jeadr/62/
$("#e1").select2();
$("#checkbox").click(function(){
if($("#checkbox").is(':checked') ){
$("#e1 > option").prop("selected","selected");
$("#e1").trigger("change");
}else{
$("#e1 > option").removeAttr("selected");
$("#e1").trigger("change");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment