jquery - Passing parameters to callbacks JavaScript -
i callback function fire after click event. have javascript
$('#btnsubmit').click(function () { $('#testdiv').hide('slow', oncomplete('test')); }); var oncomplete = function (t) { $('#hiddendiv').hide(); alert(t); }
the callback function supposed fired after hiding of #testdiv
. however, oncomplete function fires first. if remove parameters on oncomplete , give reference , not invoke it, function fires @ right time, can't pass parameters it. how can pass parameters oncomplete , not have fire before div finished hiding?
fiddle here
you have have anonymous function there wrapping oncomplete()
:
$('#btnsubmit').click(function () { $('#testdiv').hide('slow', function () { oncomplete('test') }); });
demo here
in jquery docs:
complete
type: function()
function call once animation complete.
when adding oncomplete()
without wrapping function function called immediately, otherwise need reference oncomplete
, cannot pass value unless use .bind()
pass parameter.
Comments
Post a Comment