Skip to content

Instantly share code, notes, and snippets.

@Lif3line
Created May 27, 2014 07:51
Show Gist options
  • Save Lif3line/557ff8e1fc54d52d950f to your computer and use it in GitHub Desktop.
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
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