Created
March 1, 2013 17:22
-
-
Save carusog/5066230 to your computer and use it in GitHub Desktop.
What to use instead of `toggle(…)` in jQuery > 1.8
http://stackoverflow.com/questions/14382857/what-to-use-instead-of-toggle-in-jquery-1-8
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
$.fn.toggleClick = function(){ | |
var methods = arguments, // store the passed arguments for future reference | |
count = methods.length; // cache the number of methods | |
//use return this to maintain jQuery chainability | |
return this.each(function(i, item){ | |
// for each element you bind to | |
var index = 0; // create a local counter for that element | |
$(item).click(function(){ // bind a click handler to that element | |
return methods[index++ % count].apply(this,arguments); // that when called will apply the 'index'th method to that element | |
// the index % count means that we constrain our iterator between 0 and (count-1) | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment