jquery – find()或children()只为一个样式搜索顶级子项?

我想找到一个子元素是否存在,它应用了两种类型样式.我的代码如下所示:
var listofMatchedResults = $("#parentList").find(".myStyle1,.myStyle2");

我的样式定义如下:

.parent li,.myStyle0 {
}

.parent li.myStyle1 {
}

.parent li.myStyle2 {
}

我不需要比孩子级别更深入地遍历一个级别,例如:

<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>

我不清楚find()正在做什么,它是否也会进入每个段落元素?我只需要它来遍历顶级孩子 – 有没有办法指定它?

谢谢

解决方法

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?

是的,使用.children()

来自API Doc:

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

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...