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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:18:30+00:00 2026-05-27T19:18:30+00:00

Hi have a function to console the array, and it works fine. this is

  • 0

Hi have a function to console the array, and it works fine.

this is my function :

var arrayLength = outFitLinks.length-1;
    var depthCount = 0;
    for(i=1;i<=arrayLength;i++){
        $('.cloneFrame').clone().removeClass('cloneFrame').each(function(){
            i % 2 == 1 ? $(this).attr('id','id'+i).appendTo('.front') : $(this).attr('id','id'+i).appendTo('.back');
            $(this).find('.product-frame').each(function(index){
                depthCount += 1;
                $(this).find('img').attr('src', 'imgs/outfits/'+depthCount+'.jpg');
                $(this).find('a').each(function(){
                    console.log(outFitLinks[i][index]); 
                })
                $(this).parent().hide();
            })
        })

    }
    $('.cloneFrame').remove();

at the same function i changed to console to bind to click event, it’s not working.. anything wrong?

this is the function not working :

var arrayLength = outFitLinks.length-1;
    var depthCount = 0;
    for(i=1;i<=arrayLength;i++){
        $('.cloneFrame').clone().removeClass('cloneFrame').each(function(){
            i % 2 == 1 ? $(this).attr('id','id'+i).appendTo('.front') : $(this).attr('id','id'+i).appendTo('.back');
            $(this).find('.product-frame').each(function(index){
                depthCount += 1;
                $(this).find('img').attr('src', 'imgs/outfits/'+depthCount+'.jpg');
                $(this).find('a').bind('click', function(){
                    console.log(outFitLinks[i][index]); // not working  
                })
                $(this).parent().hide();
            })
        })

    }
    $('.cloneFrame').remove();
  • 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-27T19:18:31+00:00Added an answer on May 27, 2026 at 7:18 pm

    It doesn’t work because the event handler runs later, when the variable i (and possibly outFitLinks) has a different value from when the event was bound.

    Create a closure, so that you can preserve each value for later in a local variable:

    (function() {
      var links = outFitLinks[i][index];
      $(this).find('a').bind('click', function(){
        console.log(links);
      });
    })();
    

    Come to think of it, you already have a closure in this case, as you are using .each for the loop, so it should be enough with:

    var links = outFitLinks[i][index];
    $(this).find('a').bind('click', function(){
      console.log(links);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function: function countLitreKgSums(cProductIds){ var cLitreKgSums = new Array(); var cWeek =
this is my code and have a error: $('#map_canvas').mouseover(function(e){ console.log(e.offset().left+' '+e.offset().top) }) thanks i
This is a C# console application. I have a function that does something like
Hi i have created a Generic Array that works fine for Int,String, Float or
I have a large array in this format: var cars = [{brand:Honda,year:2002},{brand:Toyota,year:2000},{brand:Subaru,year:2009}]; The array
I have a custom logging function to log to the firebug console that looks
I current have the following which works well: channel.bind('pusher:subscription_succeeded', function(members) { members.each(set_status_online); }) function
I have Javascript array which contains User object. I have created this array from
All, I am really stuck/ confused at this point. I have an array with
I have this form: $form = array( '<form name=backup-form class=backup-form method=post action=#>', '<fieldset class=backup-fields>',

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.