Created
May 27, 2014 07:51
-
-
Save Lif3line/557ff8e1fc54d52d950f to your computer and use it in GitHub Desktop.
Generalised toggling of an element using jQuery; could be a button, a panel that opens/closes, pause button etc
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
function toggle(id, callbackOn, callbackOff) { | |
if($('#' + id).data("toggledOn")) { // Turn off | |
$('#' + id).data("toggledOn",false); | |
callbackOff(); | |
} else { // Turn on | |
$('#' + id).data("toggledOn",true); | |
callbackOn(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment