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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:11:41+00:00 2026-05-22T03:11:41+00:00

I have following code for (var i = 0; i < that.$el.mini.length; i++) {

  • 0

I have following code

for (var i = 0; i < that.$el.mini.length; i++) {
            var pag = that.$el.mini[i].pagination;
            // Mini-Slider Pagination
            $('li', pag).each( function(j, el) {
                $(el).click( function() {
                    /*
                     * Toggle Mini-Slide
                     */
                    that.slider_fn.mini.show(i, j);
                    return false;
                });
            });
        }

So, basically, what I want to do is run this function that.slider_fn.mini.show(i, j); when the element is clicked.

The problem is that I want to use the variable i, which changes its value in the loop. When the element is clicked, i is valued as the latest number, that is that.$el.mini.length.

How can I make JavaScript (or a function) to memorize that particular number?

  • 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-22T03:11:42+00:00Added an answer on May 22, 2026 at 3:11 am

    Use a closure to close over the value of i:

    $(el).click( (function(i_){
      return function() {
         that.slider_fn.mini.show(i_, j);
         return false;
      };
    })(i));
    

    Beforehand, your function was referencing the variable called i, now on each iteration you create a new function that references i_, and this variable is unique to each function and references the value of i when the function was created.

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

Sidebar

Related Questions

Say I have the following code: var album = new MyObject('album'); Assume that when
I have the following code: var string = word1;word2;word3,word4,word5,word6.word7; function ends_with(string, character) { var
I have a problem with JQuery Toggle. I have the following code: var $_
I have the following code that I want to slim down. $('#1').hover(function() { $('#hiddenMenu1').css('display',
I have the following code: var tempIdx = document.getElementById('cityBuild').selectedIndex; var tempBuilding = document.getElementById('cityBuild').options[tempIdx].value; //
How do I access user preferences in Firefox? I have the following code: var
I have the following code in my controller: public ActionResult Details(int id) { var
I have code similar to the following in many places: var dbParams = db.ReadParams(memberID,
I have the following code var section = new CustomConfigurationSection(); section.SectionInformation.Type = System.Configuration.NameValueFileSectionHandler; section.SectionInformation.SetRawXml(sectionXml);
Hi I have following JavaScript code that I am trying to run. My aim

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.