2011-06-21 39 views
0

因为我有不止一个正确答案之外,我回答jQuery的发现 - 如果类元素“.myclass”是身体内,但其他元素

感谢您的帮助

这是这里的溶剂

$('body')。children('。class_to_find');

谢谢

对不起,例如,这种降价系统不好。

我可以有我的文件在同一个班超过10元,但我只是需要找到那些谁是任何元素,但身体外部,例如

<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'); 

确实抓住所有,因为他们都在体内,我该怎么办?

+0

你是什么意思时,你说身体之外?在你的例子中,这两个元素都在身体标记 –

回答

7

使用直接亲子选择:

$('body > .class_to_find').... 

.children(),其中仅搜索直接的子孙:

$('body').children('.class_to_find')... 
+0

谢谢,大家解决了这个问题,我该怎么办?我不能把所有的答案都作为正确答案 – Pluda

+0

@Pluda正常程序是'接受'最完整的答案;-) – Alnitak

3

您需要使用children方法,因为它仅在直接子女内搜索。

尝试:

$('body').children('.class_to_find'); 
+0

完美!谢谢你的帮助:-) – Pluda

1

从你的问题,它的声音像这样会工作:

$('body').children('.class_to_find'); 
+0

完美!谢谢你的帮助:-) – Pluda

相关问题