【发布时间】:2014-10-23 23:18:02
【问题描述】:
这也应该适用于 IE8
我的 tr rows 元素有多个 td 元素,每个 td 包含多个 div。一些 div 具有“cell-data”类
在一排的所有这些 div 中。我正在尝试使用“cell-data”类查找和操作 second 和 third div
我可以正确获得第一个孩子,但不能正确获得第三个孩子。我在这里搜索 SO 也试过 eq() 方法但还是找不到。
$( ".rows" ).each(function() {
var height = $(this).find('.cell-data:nth-child(1)').css("height");
var height3= $(this).find('.cell-data:nth-child(3)').css("height") ;
});
而 Html 看起来像这样
<tr class="rows">
<td class="cell-td">
<div class="row">
<div class="col-3">
<div>
</div>
</div>
<div class="col-3">
<div class="cell-data">
</div>
</div>
</div>
</td>
<td class="cell-td">
<div class="cell-data" >
</span>
</div>
</td>
<td class="cell-td">
<div class="cell-data">
</div>
</td>
</tr>
【问题讨论】:
-
你也可以粘贴 HTML 吗?
-
你能对剩下的代码做个小技巧吗?
-
请记住,
nth-child()不适用于某些版本的 IE -
@Spring 向我们展示您的标记。
-
它不适用于 CSS,但这是 jQuery 选择器 - jQuery 实现了自己的搜索,所以它应该可以工作。
标签: javascript jquery html