我想找到一个子元素是否存在,它应用了两种类型样式.我的代码如下所示:
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.
原文地址:https://www.jb51.cc/jquery/178600.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。