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

  • Home
  • SEARCH
  • 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 7746839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:22:58+00:00 2026-06-01T10:22:58+00:00

So, I have this simple code $(‘#info_name’+index).show(slide, {direction: right}, 1000, function(){ $(‘#info_info’+index).show(‘slide’,{direction: up}, 1000);

  • 0

So, I have this simple code

$('#info_name'+index).show("slide", {direction: "right"}, 1000, function(){
    $('#info_info'+index).show('slide',{direction: "up"}, 1000);
});

The i is declared upper as just a variable var i=0, but in callback, function I can’t see it…

  • 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-01T10:22:59+00:00Added an answer on June 1, 2026 at 10:22 am

    There is a scope issue with i. Since i is declared in the outer scope, all callbacks will reference the same i, meaning, if i is changed, all callbacks’ references to i will also be changed.

    What you can do is to create a function to generate the callback, since a new scope is created in that case, the value of i will be preserved.

    Based on the original question, I simplified the code a little bit. You’ve since edited it, and I can’t find the callback anymore… but hope this might help ya

    var getCallback = function(index) {
        return function(){
            // You can see how this index is being captured correctly in Javascript console
            console.log(index);
            $('#name' + index).show('slide',{direction: "up"}, 1000)
        };
    };
    
    for (var i = 0; i < 3; ++i) {
        $('#name'+i).show("slide", {direction: "right"}, 1000, getCallback(i));
    }
    

    JSFiddle: http://jsfiddle.net/vd9Mj/​

    UPDATE:

    Where’s your callback…? It seems you’ve removed it from the question.

    var i=-1;
    
    var doStuff = function(index) {
        $('.third').append('<div class="showinfo"><h3 id="info_name'+i+'" class="info_name">'+contact_name[index]+'</h3><span class="info_info" id="info_info'+index+'"><strong>'+contact_information[0][0]+'</strong>: '+contact_number[index]+'</span></div>');
        $('#info_name'+index).show("slide", {direction: "right"}, 1000);
        $('#info_info'+index).delay(1000).show('slide',{direction: "up"}, 1000, function() {
           // Insert code for callback.
        });
    };
    
    $.each(contact_status, function(key, value){
        i++;
        if(value == info_id){
            doStuff(i);
        }
    });
    ​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code that speaks for itself. <script language='javascript"> function check() {}
I have this simple code in my user_controller.rb file #listing all users def index
I have this simple code: <html> <head> <script src=jquery-1.5.1.min.js type=text/javascript></script> <script type=text/javascript> $(function() {
I have this simple code to test that a DB is ready: Function testlocalcon()
i have this simple code http://jsfiddle.net/U4Fj9/ the index of the visible image is always
I have this simple piece of code in jQuery $(document).ready(function() { $('#switcher').click(function(event) { if
I have this simple code: $('.featureItems li').hover( function(){ $(this).addClass('hover') }, function(){ $(this).removeClass('hover') } )
I have this simple jQuery code $(document).ready(function() { $('#test').attr('value','hello world'); $('#test1').text('hello world'); }); And
I have this simple code here, nothing too advanced. $(input#send).submit(function(event){ event.preventDefault(); $.ajax({ type: 'POST',
I have this jQuery simple code: <script type=text/javascript> <!-- jQuery(function(){ jQuery('#old_thumb').click(function(){ $(this).val($(this).attr('title')); $('#sf').val('2'); $('#add_new_event').submit();

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.