That's broadly right, but my problem is string concatenation. I'm
passing the div name to search for those <span>s in using a function,
so when I try to do:

var spanName = "span_"+levelID;

I just get a value of 'span_+levelID' for $spanName.

Matt

On Nov 7, 4:05 pm, "Alex Mcauley" <[EMAIL PROTECTED]>
wrote:
> okay i am trying to get this correct ..
>
> You want to see if a certain amount of spans in an element have a class name
> of 'complete' and if so do something else
>
> firstly you can easily count the amount with $$
>
> var $complete=$$('.complete').length
>
> then you want to do something if they are more than or equal to 3
>
> if(($complete) && ($complete>=3) {
>
> do_something();
>
> }
>
> is this correct so far ..
>
> Sorry i am having trouble deciphering what you want to achieve
>
> Alex
>
> ----- Original Message -----
> From: "Matt Andrews" <[EMAIL PROTECTED]>
> To: "Prototype & script.aculo.us" <prototype-scriptaculous@googlegroups.com>
> Sent: Friday, November 07, 2008 3:41 PM
> Subject: [Proto-Scripty] Re: testing whether all elements in a div have a
>
> certain class
>
> Can anyone help? I'm really close to solving this, I just need someone
> with a better grasp of Javascript to prod me in the right direction...
>
> On Nov 3, 9:51 am, Matt <[EMAIL PROTECTED]> wrote:
> > On Nov 1, 4:38 pm, Jarkko Laine <[EMAIL PROTECTED]> wrote:
>
> > > 1) your alerting with a string "bar" there.
> > > 2) $$ returns an array of elements. If you want a single item, why not
> > > give the span a unique id and call it with $? If you need to use the
> > > double-dollar selector, you need to get the first element of the array
> > > to get the actual element: $$('#container_'+boxID+' span')[0]; One
> > > option that gives you the span element (with the html syntax you
> > > posted before) is this: $('container_' + boxID).down('span').
>
> > > > <a href="#" onclick="foo("24");">click here</a>
>
> > > > // returns "$$('#container_24 span')";
>
> > > You mean the function above alerts that string? Frankly, I don't
> > > believe you :-)
>
> > > The parameter that $ and $$ take is just a normal string. There's
> > > nothing magical about it. So if you can do "string" + someVar, and the
> > > result is a string, you can give it as a parameter to those functions.
>
> > > //jarkko
>
> > I tried out those methods (the [0] ending and the .down function),
> > neither worked. I'm still struggling to get my head around this - I
> > can only pass the ID of the element through a function, so it's always
> > going to be a variable, I can't know it in advance. Here's some actual
> > code (the above stuff was a simplified (and badly-written...)
> > function, not the actual one):
>
> > //contained within my function:
>
> > var spanName = "span_"+levelID; //levelID is passed in the function
> > var spanArray = document.getElementsByClassName(name); // gets all
> > the elements I want to test
> > var completeArray = spanArray.getElementsByClassName('complete'); //
> > should get all elements within the above array with a class of
> > 'complete'
>
> > // if the number of spans is the same as the number of spans with
> > 'complete' class:
> > if(spanArray.size() == completeArray.size()) {
> > $('level2_click_1').removeClassName('incomplete');
> > $('level2_click_1').addClassName('complete');
> > $('level2_click_1').update("ON");
> > } else {
> > $('level2_click_1').removeClassName('complete');
> > $('level2_click_1').addClassName('incomplete');
> > $('level2_click_1').update("OFF");
> > }
>
> > HTML:
>
> > <span class="span_1 incomplete" id="level3_click_1">
> > <a href="javascript://" onclick="changeState('level3', '1',
> > 'on')">OFF</a>
> > </span>
>
> > <span class="span_2 incomplete" id="level3_click_2">
> > <a href="javascript://" onclick="changeState('level3', '2',
> > 'on')">OFF</a>
> > </span>
>
> > <span class="span_3 incomplete" id="level3_click_3">
> > <a href="javascript://" onclick="changeState('level3', '3',
> > 'on')">OFF</a>
> > </span>
>
> > ####
>
> > Basically, when all three of those spans have class name
> > 'complete' (eg, are turned on) I want a different span somewhere else
> > (the 'level2_click_1' span, which I will need to turn into a variable
> > rather than a hardcoded reference) needs to switch to 'complete' too.
>
> > Does this make any more sense now?
>
> > Matt
>
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to