Skip to content

Instantly share code, notes, and snippets.

@nisar1
Created March 13, 2014 06:33
Show Gist options
  • Save nisar1/9522855 to your computer and use it in GitHub Desktop.
Save nisar1/9522855 to your computer and use it in GitHub Desktop.
toggle function in jQuery
jQuery(document).ready(function () {
jQuery.fn.clickToggle = function (func1, func2) {
var funcs = [func1, func2];
this.data('toggleclicked', 0);
this.click(function () {
var data = jQuery(this).data();
var tc = data.toggleclicked;
jQuery.proxy(funcs[tc], this)();
data.toggleclicked = (tc + 1) % 2;
});
return this;
};
jQuery("#expand").clickToggle(function () {
jQuery(".dropdown ul").css('display', 'block');
jQuery(this).text("Collapse");
},function() {
jQuery(".dropdown ul").css('display', 'none');
jQuery(this).text("Expand");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment