For a code piece like this:
var clicked = function(){
alert('clicked')
}
$(".click").live("click",clicked);
The "clicked" function could be triggered multiple times in certain circumstance, on which I haven't research further yet.
But one solution to this is to remove the binded event before binding/live it, sth like:
$(".click").die("click").live("click",clicked);
or
$(".click").unbind("click").bind("click",clicked);
I have tried both of those two lines of code and it works fine. The only difference is to remove a "bind-ed" event, "unbind" is the function. While for the "live" event, it's the function of name "die".
Of course it's similar to other event like "onchange",just make sure the "onchange event" died before make it live (again):
var changed= function(){
alert('changed')
}
$(".select").die("change").live("change",changed);
Comments
pranacoder (not verified)
14 March, 2012 - 22:41
Permalink
Thanks a lot! You saved me a
Thanks a lot! You saved me a headache
Add new comment