tags:

views:

35

answers:

1

Hi,

I'd like to find if a child element exists which has either of two class styles applied. My code looks like this:

var listOfMatchedResults = $("#parentList").find(".myStyle1, .myStyle2");

My styles are defined like this:

.parent li, .myStyle0 {
}

.parent li.myStyle1 {
}

.parent li.myStyle2 {
}

I don't need to traverse more than one level deeper than the children level, like:

<ul id='parentList'>
    <li><p>foo</p><p>grok</p></li>
    <li class='myStyle2'><p>Here</p><p>I am!</p></li>
    <li><p>foo</p><p>grok</p></li>
</ul>

I'm not clear as to what find() is doing, is it going into each of the paragraph elements too? I just need it to traverse the top-level children - is there a way to specify that?

Thank you

+3  A: 

I'm not clear as to what find() is doing, is it going into each of the paragraph elements too?

yes it does

I just need it to traverse the top-level children - is there a way to specify that?

yes, use .children()

From API Doc:

The .find() and .children() methods are similar, except that the latter only travels a single level down the DOM tree.

jAndy
Pithy, though concise.
MvanGeest
@Mvan - Pithy and concise are synonymous. :o)
patrick dw
If I remember correctly, it's a quote from "Angela's Ashes" by Frank McCourt. I might be able to look it up, the e-book should be somewhere. *searches*
MvanGeest
@Mvan - Just give you a little bit of a hard time. ;o)
patrick dw