How to use Callback function in JQuery

In this article I have described that how to use callback function in webpage with help of jQuery.
  • 1857

Callback In JavaScript

  • To create effective webpage, we use jQuery in our JavaScript code of webpage.
  • When the current effect is finished then callback function is executed.

Syntax

Lets take an example to hide the information, then we have to use the syntax

<script type="text/javascript">

    $(document).ready(function () {

        $("button").click(function () {

            $("div").fadeTo("slow", 0.30);

        });

    });

</script>

 

Example - After hiding the information, the alert box is appeared .

 

<!DOCTYPE html>

<html>

<head>

    <script src="jquery-1.7.2.min.js" type="text/javascript"></script>

<script type="text/javascript">

    $(document).ready(function () {

        $("button").click(function () {

            $("h2").hide(1000, function () {

                alert("Now there is no information");

            });

        });

    });

</script>

</head>

<body>

<button>Hide</button>

<h2>Welcome to Callback function in JQuery</h2>

</body>

</html>

 

OUTPUT

 

 

When we click on Hide button


JQ CLBCK FIG2.jpg

 

You may also want to read these related articles here

Ask Your Question 


Got a programming related question? You may want to post your question here
© 2019 DotNetHeaven. All rights reserved.