Skip to content

Instantly share code, notes, and snippets.

@Amitesh
Created May 6, 2015 06:34
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 Amitesh/6751f35dc8934d695c75 to your computer and use it in GitHub Desktop.
Save Amitesh/6751f35dc8934d695c75 to your computer and use it in GitHub Desktop.
Click Toggle jQuery Plugin
(function($) {
$.fn.clickToggle = function(func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function() {
var data = $(this).data();
var tc = data.toggleclicked;
$.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
}(jQuery));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment