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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:30:45+00:00 2026-05-28T06:30:45+00:00

There are topics about this, but not realy pointed at my problem. I’m using

  • 0

There are topics about this, but not realy pointed at my problem.

I’m using iScroll, a jquery plugin. For every scrollbox on my page I need to assign a unique variable. In this case it’s gonna be myScroll1, myScroll2 etc.

To make it easily editable, I want the variables to be automatically generated giving the number of div’s in wich the scrollbars are in. So, let’s say I have 2 divs with these scrollbars. I use the .size() method to count the divs. Then I want a while loop to make the variables. I now have something like this:

var i = 0;
var item_number = $(".portfolio_item").size();

var myScroll = [];
while( i < item_number ) {
    myScroll[i];
    i++;
}

Sooo, I don’t want anything generated in the HTML, just the variables. They have to become myScroll1, myScroll2, myScroll3. Depending on the amount of .portfolio_item divs.

I have tried this with php, that’s a bit easier for me. But!! I can’t use javascript variables in php. So I can’t count the amount of .portfolio_item divs 🙁
Thank you! 🙂

  • 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-28T06:30:46+00:00Added an answer on May 28, 2026 at 6:30 am

    Bad practice, but you can do this

    var i = 0;
    var item_number = $(".portfolio_item").size();
    
    while( i < item_number ) {
        window["myScroll" + i] = "foo" + i;
        i++;
    }
    
    alert(myScroll0);
    

    better practice is to use a namespace and add to it.

    var i = 0;
    var item_number = $(".portfolio_item").size();
    
    var foo = {};
    while( i < item_number ) {
        foo["myScroll" + i] = "foo" + i;
        i++;
    }
    
    alert(foo.myScroll0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There have been many debates about this topic already here, but none of them
I know there are few threads about this topic. But what really confused me
OK, I've read every single topic on SO about this problem and I am
There are many discussions on this topic already, but I am all about flogging
There's a lot of conflicting information about this topic. So let's try to agree
There are several topics about what questions will be raised in an interview for
I realize there are similar questions on this topic, but I still cannot find
Hey, first, let me say, I'm not asking about things like md5(md5(..., there are
I know there are a lot of questions on this topic already, but it
I know there are a bunch of posts on this topic, but I can't

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.