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

Popular posts from this blog

SPSS keyboard combination alters encoding -

Socket.connect doesn't throw exception in Android -

iphone - How do I keep MDScrollView from truncating my row headers and making my cells look bad? -