Let’s say I have these two functions:
function z(a,b,c){
$("#d").click(function(){
var sum = a+b+c;
x(sum)
}
function x(first){
var second = first*(first+1);
var third = second*(second+1);
$("#e").animate({
"left": "+=first%"
},{
complete:function(){
z(first, second, third)
});
I want the first function [function z] to be triggered with different arguments and “unbind” its previous .click() event after the animation.
So that the first time click on #d, #e moves (a+b+c)%.
The second time click on #d, #e moves (a+b+c)+(a+b+c)*(a+b+c+1)+(a+b+c)*(a+b+c+1)*((a+b+c)*(a+b+c+1)+1)%. The third time …
I’ve tried using unbind but it didn’t seem to be fit into this situation. I ended up writing more and more messy codes. I don’t think using unbind is a smart way.
the “one()” function will ensure that your “click” event is unbound after you click it the first time.
Ref : http://api.jquery.com/one/