I am racking my brain trying to figure out how this is used properly. Most all examples use ajax so maybe this is not even possible.
In my example, I create a function, which fades out an element. I realize that .fadeOut
can have a callback but I would like to avoid that just for learning purposes.
I read that I need to return a promise or else the $.when().done()
would fire immediately. Even though I have attached a promise, it still fires right away.
Here is my simple code
function hide() {
return $("#element").fadeOut(250).promise();
}
$.when( hide() ).done(function(){
alert("Hidden");
});
Are there certain methods that can not be used with $.when()
such as .fadeOut()
?
Any help in understanding would be awesome.