tags:

views:

56

answers:

4
$("#rightCol").children().children().children("div.entry").length

I tried this

$("#rightCol").children().eq(1).children("div.entry").length

or this

$("#rightCol").children(":eq(1)").children("div.entry").length

with no success. ideas?

+3  A: 

You can do it using the child-selector (>), like this:

$("#rightCol > * > * > div.entry").length

Though, if you know the child type, I'd use that over *. If he level doesn't matter, just a descendant selector () will work.

$("#rightCol div.entry").length
Nick Craver
works! and is interesting...
Thomasz
+3  A: 

Maybe this?

$("#rightCol *:eq(1) div.entry").length
BrunoLM
This one work too, thanks!
Thomasz
+4  A: 

Depending on the layout (do you have DIVs with that class at other levels that you want to avoid?), you might get by with

$('#rightCol').find('div.entry').length
tvanfosson
This is actually a more performant way to go compared to the universal selector("*"). $(..).children() is even faster than calling $("*").
Alexis Abril
I choose this;) thx!
Thomasz
+3  A: 

This should work, if you must have the specific level in the descendant tree.

$("#rightCol > * > * > div.entry")

However, this is more normal. It would pick any "div.entry" inside of "#rightCol", regardless of the depth.

$("#rightCol div.entry")
John Fisher
Both are working, nice solutions, thanks!
Thomasz