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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T00:06:22+00:00 2026-05-20T00:06:22+00:00

Good morning people – I’ve been having this problem for hours and I can’t

  • 0

Good morning people – I’ve been having this problem for hours and I can’t isolate it.

I have this piece of jQueryzed JavaScript:

jQuery(document).ready(function() {
    var validated = 1;

    jQuery('#help_continue').click(function() {
        jQuery('#step' + validated + ', #step' + validated + '_help').fadeOut(200, function() {
            jQuery('#step' + validated + '_help').removeClass('visible').find('.visible').removeClass('visible');
            jQuery('#step' + (validated + 1) + '_help').addClass('visible');
            jQuery('#step' + (validated + 1) + '_help div:first').addClass('visible').css({display: 'block'});
            jQuery('#step' + (validated + 1) + ', #step' + (validated + 1) + '_help').fadeIn(200);
        });
    });
});

All good, nothing too fancy. If bound to HTML, it works as expected.

The thing is that, when I add this to the mix:

jQuery(document).ready(function() {
    var validated = 1;

    jQuery('#help_continue').click(function() { 
        jQuery('#step' + validated + ', #step' + validated + '_help').fadeOut(200, function() {
            jQuery('#step' + validated + '_help').removeClass('visible').find('.visible').removeClass('visible');
            jQuery('#step' + (validated + 1) + '_help').addClass('visible');
            jQuery('#step' + (validated + 1) + '_help div:first').addClass('visible').css({display: 'block'});
            jQuery('#step' + (validated + 1) + ', #step' + (validated + 1) + '_help').fadeIn(200); alert(validated); // this...
        });
        validated++; // ...and this.
    });
});

The alert it shown TWICE, and the “validated” variable is NEVER = 1 inside the function – always 2.

I’m no JavaScript guru for sure, but I definitely know that that’s just plain wrong, unless I’m missing something. I come from a PHP background, and I know that JavaScript has its idiosyncrasies, but this is just weird.

I’m using jQuery 1.5 if it matters. Anyone knows what’s happening?

  • 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-20T00:06:23+00:00Added an answer on May 20, 2026 at 12:06 am

    The code you pass as callback to fadeOut is only executed after ~200ms timeout. But the the code is not blocking. I.e. everything inside the click handler, also statements after the call to fadeOut, is executed immediately.

    jQuery('#help_continue').click(function() {
        // first 
        jQuery('....').fadeOut(200, function() {
            // second
        });
        validated++; // first
    });
    

    But this should not show the alert twice… anyway, if you want to increment validate on click, but it should have the the correct value when the fadeOut callback is called, you can do so with an immediate function:

    jQuery('#help_continue').click(function() {       
        (function(validated) {
            jQuery('....').fadeOut(200, function() {
                // ...
            });
        }(validated));
        validated++;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning. I've been having this issue for some days and have been lokking
Good Morning Stack OverFlow enthusiasts. I have been having an issue that I am
Good Morning, I have copied this code from somewere <script type=text/javascript> $(function() { setInterval(rotateImages(),
Good morning! We have a SVN-Repository, which holds a VS-Solution. In this solution are
Good Morning, I have a SharePoint site that I've been trying to fix up
Good morning, I have problem with using MasterPage and jQuery. I using jQuery UI
Good morning I have been running a few tests over the past couple of
Good Morning, I have Stuck in a strange problem. I want to open PDF
Been banging my head against this all morning. Basically, I have a listbox, and
Good morning all, happy thursday morning. I wish I could have done this by

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.