Skip to content

Instantly share code, notes, and snippets.

@lishiyo
Last active August 29, 2015 14:03
Show Gist options
  • Save lishiyo/3e6fb4e9d0c4a2cfe708 to your computer and use it in GitHub Desktop.
Save lishiyo/3e6fb4e9d0c4a2cfe708 to your computer and use it in GitHub Desktop.
methods for toggling between states
//general toggling - use another variable
var x = 0;
$('#toggle-btn').click(function(e){
if( x == 1 ){
$(this).removeClass('clicked');
x = 0;
} else {
$(this).addClass('clicked');
x = 1;
}
e.preventDefault();
});
//checkboxes only - toggles between each checkbox's state
$('#select').click(function(){
$('input[type=checkbox]').trigger('click');
});
$("#select").click(function(){
$("input").each (function() {
this.checked = !this.checked;
});
});
//.prop( propertyName, valueToSet) - toggles selectAll and selectNone
$(document).ready(function() {
$("button").click(function() {
var checkBoxes = $("input[name=recipients\\[\\]]");
checkBoxes.prop("checked", !checkBoxes.prop("checked"));
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment