Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • jQuery Callback Functions

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 201
    Comment on it

    JavaScript codes are executed line by line. However, the next line of the code can run even though the effect of the first line of code is not finished. This can create errors.

    To prevent this errors, we can create a callback function. callback function will minimize the error that is affected during current effects. A callback function is executed after the effects is finished of the last line code.

    The example below has a callback parameter that is a function that will be executed after the hide effect is completed:

    $("button").click(function(){
        $("p").hide("slow", function(){
            alert("The paragraph is now hidden");
        });
    });

    The below code has no callback parameter and alert box will be displayed before the hide effect is completed

    Example without Callback-

    $("button").click(function(){
        $("p").hide(1000);
        alert("The paragraph is now hidden");
    });

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: