views:

132

answers:

2

I use MooTools, and I need to find the element which has both classes "a" and "b" (the innermost div in my example below).

The HTML structure is:

<div class="a">
   <div class="otherclass">
      <div class="b"></div>
   </div>
 </div>

In jQuery it's $("div .a .b"), as far as I know. What's the mootools syntax? I've tried

$$("div .a .b")

but it doesn't return any results.

Thanks!

-- To clear things, I want to get ONLY the divs which have both classes (in this case, only one.) thanks.

+1  A: 

What about

$$('div.a div.b')

or

$$("div.a").getElements("div.b");
rahul
I think 'div.a div.b' gives too wide results (meaning not only divs who have both "a" and "b" classes but also those who are only "b" or only "a").Regarding the second method, isn't there a shorter css-like way to define the selector?thanks.
Nir
+1  A: 
var divsB = $$("div.a div.b");

http://mootools.net/shell/jfnWK/ - selects the first one but not the second as it's not a child of a div.a

Dimitar Christoff
thanks a lot for the excellent tool. The expression you gave gives the wrong output: The result is 1 2, which means I'm also getting the div which has only class "b", and I'd like to get only those who have both "a" and "b".
Nir
you really ought to look at the firefox / whatever browser console - it will only return the first instance. you see 1 2 for illustration purposes as html - this is not what the selector returns.your original selector is wrong - you are calling any div elements that have any child class elements "a" that have any child class elements "b" - so it's a level 3 selector and one that will be identical in mootools -> div -> a -> b, not div.a -> div.b which matches your markup.
Dimitar Christoff