Reputation: 13372
Here's what I would like to do in pseudocode form.
Bind Two Functions to Click Event
On 1st/Odd Clicks Do FunctionA()
On 2nd/Even Clicks Do FunctionB()
The .toggle() function seems to not be designed for this.
I'm sure this exists in jQuery but my googling hasn't resulted in anything. :)
Upvotes: 1
Views: 1239
Reputation: 237817
I don't see how this isn't exactly what toggle
is designed for...
$('#someEl').toggle(FunctionA, FunctionB);
You may be confused by the other toggle
function that exists in jQuery, which won't be called if you pass functions as the arguments.
Upvotes: 4
Reputation: 384
You just need to ask Google the right question ;)
$(selector).toggle(function(),function(),function(),...)
http://www.w3schools.com/jquery/eff_toggle.asp
Upvotes: 0
Reputation: 148514
var i=1;
$(".a").click (function () {if (i%2!=0) FunctionA();i++;});
$(".a").click (function () {if (i%2==0) FunctionB();i++;});
Upvotes: 1