javascript jquery callback accumulates
Issue: Each time div.a is clicked, the number of callbacks when div.b is
clicked,accumulates by 1.
var $=jQuery;
$(function(){
$("div.a").click(function(){cbf(trgmsg);});
});
function trgmsg(){
alert($.now());
}
function cbf(cb){
$("div.b").click(function(){cb()});
}
Result:
click div.a once and click div.b => alert() pops-up;
if i click div.a again and click div.b => alert() pops-up twice
consecutively;
if i click div.a another time and click div.b => alert() pops-up three
times consecutively;
..and so on
I have No idea what the cause of the problem is or if its simply my
misunderstanding/misuse of callback functions in JS. Any insights and/or
advice will be greatly appreciated. thanks
No comments:
Post a Comment