Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9248967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T10:04:46+00:00 2026-06-18T10:04:46+00:00

The callback on my custom function is not working. Please would anyone help me

  • 0

The callback on my custom function is not working. Please would anyone help me ?

<html>
<body>
<script src='jquery-1.8.2.js'></script>
<script>
$(document).ready(function(e){
  function cb(){
    alert('animation finish');
  }
  $('button').bind({
    'click':function(e,cb){
        e.preventDefault();
        $('div').animate({'height':200,'width':200},1000);
        cb();
     }
  })
})
</script>
<style>
div{
  height:5px;width:5px;background-color:yellow;
}
</style>

<button>click me</button>
<div></div>

</body>
</html>

edited:
I cannot do the .animate(...,1000,function(){...})
I used the line

$('div').animate({'height':200,'width':200},1000);

just to represent some other functions in execution — it is relative complicated, with more conditions, and different animations called depending upon various parameters.

Basically, after all those animations are over, I want a end function cb() to execute; which is where I am having the problem.

Maybe something like this would be appropriate :

<script>
$(document).ready(function(e){
  var status=0;
  var tmp1=2;tmp2=7;
  function cb(){
    alert('animation finish');
    console.log(status);
  }

  function do_func1(){
     status = tmp1+tmp2;
     $('#ele1').animate({'height':200,'width':200},1000);
  }
  function do_func2(){
     status = tmp1*tmp2;
     $('#ele2').animate({'height':300,'width':300},2000);
  }
  function do_func3(){
     status = tmp1+tmp1;
     $('#ele3').animate({'height':400,'width':400},500);
  }

  function func1(){
     if('a'=='b'){
         do_func1();
     }else if('a'=='c'){
         do_func2();
     }else{
         do_func3();
     }
  }

  $('button').on({
    'click':function(e,cb){
        e.preventDefault();
        func1();
        cb();
     }
  })
})
</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T10:04:47+00:00Added an answer on June 18, 2026 at 10:04 am

    you can do somthing like this

      <script>
    
        function cb(){
            alert('animation finish');
        }
    
        //-----------------------
        $(function()
          {
            $('button').on('click',function(e)
              {
                  e.preventDefault();
                  var steps=0;
                  var totalSteps=5;    // for example
    
                  var checking=setInterval(function()
                                           {
                                             if(steps===totalSteps)
                                             {
                                               cb();
                                               clearInterval(checking);
                                             }
                                           },30);
    
                $('div').animate({'height':200,'width':200},1000, function(){steps++;});
                $('div').animate({...  another animation  },1000, function(){steps++;});
                ...
                $('div').animate({...  another animation  },1000, function(){steps++;});
    
    
             })  // ..on
        }) // ready function
     </script>
    

    you can also change the step++ to anything else you want, and then write a proper condition inside the checking function in order to act upon it…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote a custom jquery function that accept a callback but not being able
My custom function is not working. I am checking if passed value does not
I have a function that I use as a callback for a custom event:
I am utilising the callback function of jQuery's .load method to run certain code
The jQuery File Upload plugin does NOT currently display the selected file. Does anyone
Is there a way to pass more data into a callback function in jQuery?
I am writing an custom callback function in Fortran for a piece of software
I've got a custom Javascript class that generates a JQuery mousedown callback. The mousedown
JQuery has great support for custom events - .bind(foo, function(e)... . However what if
I am trying to get this Jquery count-up function to work but it's not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.