[英]Table Row Traversing with JavaScript jQuery
I have a table formatted like that following: 我有一个表格,格式如下:
<table>
<tbody>
<tr class="node">
<td onclick='toggleDesc(this.parentNode);'>blah</td>
</tr>
<tr class="subnode">
<td>sblah</td>
</tr>
<tr class="subnode">
<td>sblah</td>
</tr>
<tr class="subnode">
<td>sblah</td>
</tr>
<tr class="node">
<td onclick='toggleDesc(this.parentNode);'>blah</td>
</tr>
<tr class="subnode">
<td>sblah</td>
</tr>
<tr class="subnode">
<td>sblah</td>
</tr>
</tbody>
</table>
I also have a function that toggles the display of the .subnode
classes based on the TD of the .node
above it. 我还有一个函数,可以根据其上方.node
的TD来切换.subnode
类的显示。 The function looks like this: 该函数如下所示:
function toggleDesc(item) {
var descRow = item.nextElementSibling;
$(descRow).toggleClass("descDisplay");
}
However, the function above only toggles the display of the first .subnode
it encounters. 但是,上面的函数仅切换其遇到的第一个.subnode
的显示。 Does anyone know how to .toggleClass
for each .subnode
after .node
until the next .node
is hit? 有谁知道如何.toggleClass
每个.subnode
后.node
,直到下一个.node
被击中?
Use nextUntil()
: 使用nextUntil()
:
$(item).nextUntil('tr.node').toggleClass("descDisplay");
See Documentation 请参阅说明文件
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.