jquery选择嵌套div [英] jquery select nested div
问题描述
如何选择包含我的内容的div?
How do I select div that contains "my content"?
<table>
<tr>
<td class="ms-disc-bordered-noleft">
<div class="">
<div>some content</div>
<div>my content</div>
</div>
</td>
</tr>
</table>
div与td.ms-disc-bordered-noleft有什么关系?
what relation does that div has with td.ms-disc-bordered-noleft?
推荐答案
-
$('。ms-disc-bordered-noleft div:last')
-
$('。ms-disc-bordered-noleft
div:eq(2)') -
$('。ms-disc-bordered-noleft')。find('div:eq(2)');
- 或
$(div:contains('my content'):last);
$('.ms-disc-bordered-noleft div:last')
$('.ms-disc-bordered-noleft div:eq(2)')
$('.ms-disc-bordered-noleft').find('div:eq(2)');
- or
$("div:contains('my content'):last");
返回droid ...我的意思是div ...您正在寻找。
return the droid...I mean div...you are looking for.
我有一种感觉, $('。ms-disc-bordered-noleft div:last')
我的效果测试表明,它通常是4个提案中最快的(FireFox喜欢 $('。ms-disc-bordered-noleft')。find('div:eq(2)');
)
I have a feeling that $('.ms-disc-bordered-noleft div:last')
is your best option; my performance test shows that it is generally the fastest of the 4 proposals (FireFox prefers $('.ms-disc-bordered-noleft').find('div:eq(2)');
).
有关不同选择器的示例,请参见 http://jsfiddle.net/jhfrench/cfeZU 使用。
See http://jsfiddle.net/jhfrench/cfeZU for examples of the different selectors in use.
至于问题的第二部分,该div是 td.ms-disc-bordered-noleft
元素。更具体地说,它是td的孩子的孩子。
As for the second part of your question, that div is a 'descendant' of the td.ms-disc-bordered-noleft
element. More specifically, it is the child of the td's child.
这篇关于jquery选择嵌套div的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!