How to execute callback functions in jQuery

author details
AdiPie
31st Dec 2020
1 min read
Image
How to execute callback functions in jQuery

Javascript commands are executed in the same order. Weather, with the visuals, the line of command could be executed when the effects are not completed. This can create issues.

To prevent the above javascript issue, You can make a jQuery callback function. It permits a designer to ensure one code line is done before the other one starts. By shaping a line of occasions, jQuery callback keeps impacts from covering and causing issues.

Syntax: $(context).hide(speed,callback);

Sample with Callback:

$("button").click(function(){
  $(".text").hide("slow", function(){
    alert("The text container is now gone");
  });
});

Sample without Callback:

$("button").click(function(){
  $(".text").hide(1000);
  alert("The text container is now gone");
});