Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Callback function won't take name of function(), must have an anonymous function

This works:

$("#formbottom").slideUp(speed,'swing',function(){
    openSubmitting();
});

This doesn't:

$("#formbottom").slideUp(speed,'swing',
    openSubmitting()
);

When you have a callback, do you always have to have an anonymous function in there? Can't you just put the function you want to call?

like image 790
Doug Cassidy Avatar asked Jan 11 '13 01:01

Doug Cassidy


2 Answers

openSubmitting() calls your function. You don't want the result of your function. You want your actual function, which is why you write function() {...} instead of (function() {...})().

Since you want to pass a reference to your function, remove those parentheses:

$("#formbottom").slideUp(speed,'swing',
    openSubmitting
);
like image 128
Blender Avatar answered Nov 07 '22 02:11

Blender


Have you tried jQuery("#formbottom").slideUp(speed,'swing',openSubmitting);?

like image 21
dunli Avatar answered Nov 07 '22 00:11

dunli