jquery - JavaScript - Passing Arguments to Anonymous Functions -
i'm calling anonymous function:
closesidebar(function() { alert("function called"); $(this).addclass("current"); settimeout(function(){opensidebar()}, 300); });
but $(this)
doesn't work expected , need pass argument function. after bit of research thought work:
closesidebar(function(el) { $(el).addclass("current"); settimeout(function(){opensidebar()}, 300); })(this);
but doesn't. how add arguments anonymous function?
jsfiddle - click button on right, animates in calls function above. when button has class "current" have white bar on left side of button class never changes.
you can this:
closesidebar(function(el) { $(el).addclass("current"); settimeout(function(){opensidebar()}, 300); }(this));
the arguments need passed anonymous function itself, not caller.
Comments
Post a Comment