Last active
August 29, 2015 14:03
-
-
Save lishiyo/3e6fb4e9d0c4a2cfe708 to your computer and use it in GitHub Desktop.
methods for toggling between states
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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