Forum: Rails Spinoffs (closed, excessive spam) can $$ do this?

Posted by elduderino (Guest)
on 2008-06-27 11:20
(Received via mailing list)
Hi,

I have this code:

var alldrags = $$('#dragGame' + gameCount '.dragMe');

But it's causing an error somehow. I''m trying to say select all div's
with dragMe class inside the dragGame (plus an incrementing number)
div but this is throwing an error saying my function is not defined.

I've also tried assigning the dragGame selector to a variable....like
so:

var dragGame = '#dragGame' + gameCount;

and then doing the selector like so:

var alldrags = $$(dragGame '.dragMe');

Both ways are throwing an error saying my function isn't defined.

Any ideas?

Thanks
Posted by Rudy Susanto (Guest)
on 2008-06-27 12:20
(Received via mailing list)
You just missed the plus (+) sign.

It should be like this:

var alldrags = $$('#dragGame' + gameCount + '.dragMe');

and

var alldrags = $$(dragGame + '.dragMe');

:)
Posted by elduderino (Guest)
on 2008-06-27 12:32
(Received via mailing list)
Hi,

Thanks for the reply. I don't think that's it....that'll give me
#dragGame1.dragMe as the + has concatenated the whole thing. I have
tried it but it doesn't work. From looking at the api docs theres an
example like this...:

$$('#contents a[rel]');
// -> all links inside the element of ID "contents" with a rel
attribute

So i'm assuming that using a space is what needs to be done to select
everything in the dragGame1 div taht has a class of dragMe.
Posted by Rudy Susanto (Guest)
on 2008-06-27 13:03
(Received via mailing list)
Then, it should be like this:

var alldrags = $$('#dragGame' + gameCount + ' .dragMe');

or more specific

var alldrags = $$('#dragGame' + gameCount + ' div.dragMe');
Posted by elduderino (Guest)
on 2008-06-27 13:07
(Received via mailing list)
YES! That's it! Why didn't i think of that?! Thanks for your time
Rudy :)
Posted by Frederick Polgardy (Guest)
on 2008-06-27 14:54
(Received via mailing list)
Right.  In CSS a space means "any descendant of."

So "div.someClass" means all divs with a class of someClass, while "div
.someClass" means any element with a class of someClass that is a 
descendant
of any div.

-Fred

On Fri, Jun 27, 2008 at 5:31 AM, elduderino 
<jamesfiltness@googlemail.com>
wrote:

> attribute
--
Science answers questions; philosophy questions answers.
Posted by Frederick Polgardy (Guest)
on 2008-06-27 14:58
(Received via mailing list)
You want a selector of:

#dragGame<n> <space> .dragMe

Where n is the value of gameCount?

That's $$('#dragGame' + gameCount + ' .dragMe').  Note the space.

You were on the right track, but in JS you always need an explicit + to 
do
string concatenation.

-Fred

On Fri, Jun 27, 2008 at 4:20 AM, elduderino 
<jamesfiltness@googlemail.com>
wrote:

>
> Hi,
>
> I have this code:
>
> var alldrags = $$('#dragGame' + gameCount '.dragMe');



--
Science answers questions; philosophy questions answers.
Posted by elduderino (Guest)
on 2008-06-27 15:14
(Received via mailing list)
Hi there,

Yes i'm ok with concatenating in javascript but i really didnt think i
needed to concatenate the dragme class on to the end...but it seems
so!

Thanks
This topic is locked and can not be replied to.