Created
March 13, 2014 06:33
-
-
Save nisar1/9522855 to your computer and use it in GitHub Desktop.
toggle function in jQuery
This file contains hidden or 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
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