BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

jQuery Callback Function

By Chaitanya Singh | Filed Under: jQuery

jQuery callback function executes when the effect is complete. In the previous tutorials we have discussed several jQuery effects, each of those methods accept callback function as a parameter that executes when the effect is finished. For example if we are passing a callback function to slideUp() method then the callback function will execute when the slide up effect is complete.

jQuery Callback Function Example

In the following example we are passing a callback function to the hide() method as a parameter, in the callback function we are setting up an alert message. Since the callback function executes when effect is finished, in this case the alert message will display once the paragraph is hidden.

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").hide("slow", function(){
      alert("The paragraph is now hidden");
    });
  });
});
</script>
</head>
<body>

<h2>jQuery callback function example</h2>
<p>This example is published on beginnersbook.com. This para
will disappear when you click on the hide button and an alert
message will display that "The paragraph is now hidden"</p>
<button>Hide</button>
</body>
</html>

Output:
Before the button is clicked:
jQuery callback function
After the button is clicked:
jQuery callback function example

❮ PreviousNext ❯

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

jQuery Tutorial

  • jQuery Tutorial
  • jQuery Selectors
  • jQuery Events

jQuery Effects

  • jQuery Show & Hide
  • jQuery Fading
  • jQuery Sliding
  • jQuery Animate
  • jQuery stop()
  • jQuery Callback Function
  • jQuery Chaining

jQuery HTML/CSS

  • jQuery html()
  • jQuery addClass()
  • jQuery hasClass()
  • jQuery removeClass()
  • jQuery toggleClass()
  • jQuery after()
  • jQuery before()
  • jQuery append()
  • jQuery appendTo()
  • jQuery clone()
  • jQuery insertBefore()
  • jQuery insertAfter()
  • jQuery attr()
  • jQuery text()
  • jQuery val()
  • jQuery css()
  • jQuery prepend()
  • jQuery remove()
  • jQuery empty()
  • jQuery detach()

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap