amitben amitben - 1 month ago 19
jQuery Question

jqueryui switchClass callback

i'm having a problem running a function after a jquery ui switchclass effect is completed.

looking into the manual it describes that
.switchClass( removeClassName, addClassName [, duration ] [, easing ] [, complete ] )

but when trying to run a:

$("#main").switchClass('primary','secondary','slow',runAfterComplete());


with a

function runAfterComplete(){
console.log("switchclass completed");
}


it runs it before it is completed.

Answer

You need to pass a function reference(runAfterComplete) as the callback, in your case you are invoking(() at the end) the runAfterComplete function and the value returned from it(undefined) as the callback to the switchClass method

$("#main").switchClass('primary','secondary','slow',runAfterComplete);
Comments