Search code examples
javascriptjqueryyuiyui3

Change var values = [2, 3, 4] to something like [all whole numbers]


Here's a another noob question.

Again working with YUI3.

How can I change:

var values = [2, 3, 4];

to include ALL whole numbers, and not just 2, 3, and 4 ?

Thanks!

EDIT:

Here's a bit of extra info.

This is what I have:

var numbers = [2, 3, 4];

for(var i = 0; i < numbers.length; i++)
{
  var boxnum = numbers[i];
  Y.all(".box"+boxnum ).addClass(boxnum );  
}

so just want to check for each possible class of . box1, .box2, .box3, .... ,but I'm not sure how many of these classes there might be.

Ta!


Solution

  • To Find all elements with class "box" + x:

    for (var x = 0; x <= 9999; x++) {
        if ($('.box' + x).length < 1) {
            $('.box' + x).addClass('yourClass');
        } else {
            break;
        }
    }
    

    This assumes you wont have box x if you don't have box (x-1). (boxes are numbered in order without any missing numbers) If this assumption is not correct, let me know.