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 6230775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:48:46+00:00 2026-05-24T09:48:46+00:00

I have a button, when clicked, animates a div. I am trying to make

  • 0

I have a button, when clicked, animates a div.

I am trying to make use of the $.animate() [complete] callback function, but running into a situation where clicking the button twice really fast causes the animation to run twice before the first animation’s [complete] callback runs.

Please see this link for demo.
http://jsfiddle.net/zs2uf/3/

Any ideas how to prevent the second click from beating the first’s callback?

  • 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-05-24T09:48:48+00:00Added an answer on May 24, 2026 at 9:48 am

    You should disable the button immediately after it is clicked, and then do the animation.

    You say you want to make it so that the button can only be clicked once, but you wait until the animation is done before disabling the button. This is why the program doesn’t behave as you wish it to, since during the animation, the button could be clicked again.

    Here is a how to make sure to button can only be clicked once:

    $("#next").click(function(){
    
        var pos = parseInt($("#box").css("left")),
            newPos = pos + 100;
    
        // disable button immediately after the click
        // if you wait to disable, you give the user the chance to click twice
        $("#next").unbind('click');
        $("#next").attr("disabled", "disabled");
    
        $("#box").animate({
            "left" : newPos //move the box to the right by 100px
        }, {
            duration: 150
        });        
    })
    

    Working example

    The unbind() may not be necessary in many browsers, but it ensures that the click event handler is actually removed from #next.

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

Sidebar

Related Questions

I have a usercontrol that hides a div when a button is clicked. <asp:LinkButton
I have the following code: var clickCount = 1; var slideCount = $('div.slide').length; $('a#next-button').click(function()
The ultimate goal is to have a div animate down when the button is
I have a button that loads more data into a datagrid when clicked. To
I have a button that when clicked will run a stored procedure on a
In my Silverlight UI, I have a button that when clicked pops up a
I have a button that opens a dialog when clicked. The dialog displays a
I have a button and when it's clicked, I want to replace the button
I have Drupal 5 site where a button is clicked and it calls a
I have a button on an ASP.NET wep application form and when clicked goes

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.