jquery find - 如果类元素“.myclass”是位于主体之内,但位于其他元素之外
由于我有多个正确答案,我正在回答
感谢您的帮助,
这是这里的解决方案
$('body').children('.class_to_find');
感谢
抱歉,示例格式错误,这个降价系统不好。
我的文档中可能有超过 1 个具有相同类的元素,但我需要找到除 body 之外的任何元素之外的元素,例如
<body>
<div class="class_to_find">my div</div>
<div class="testing">
<div class="class_to_find">my other div</div>
</div>
</body>
我只想捕获“我的 div”,但当然这
$('body').find('.class_to_find');
确实捕获了所有元素,因为它们都在身体里了,我该怎么办?
Since I've got more than one correct answer, I'm answering
Thanks for your help
this was the sollution here
$('body').children('.class_to_find');
Thanks
Sorry for bad formating of example, this markdown system in not good.
I may have more than 1 element with the same class in my document, but I need to just find those who are outside any element but body, example
<body>
<div class="class_to_find">my div</div>
<div class="testing">
<div class="class_to_find">my other div</div>
</div>
</body>
I just want to catch 'my div', but of course this
$('body').find('.class_to_find');
does catch all, since they're all within body, what should I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用直接父子选择器:
或
.children()
,它仅搜索直接后代:Use the direct parent-child selector:
or
.children()
, which only searches direct descendents:您需要使用 children 方法,因为它仅在直接子级中搜索。
尝试:
You need to use children method as it searches only within immediate children.
Try:
从你的问题来看,这听起来像是可行的:
From your question, it sounds like this would work :
试试这个
Try this