0

我需要从一个特定的地方<td>,我需要得到下一个<tbody>,showToggle 与 jQuery 一起使用。嵌套如下所示

<tbody>
    <tr>
        <td class="fromhere">something</td>
    </tr>
</tbody>
<tbody class="tohere">
     <tr>
         <td>Something</td>
     <tr>
</tbody>

我想在使用 jquery 单击“formhere”时触发“tohere”。

我试过$('.fromhere).next('tbody').showToggle(100)了,但这不起作用。我上课的原因是我有多个这样的 tbody 组合,我不想为每个组合右击,这也不是好的编码习惯。

4

2 回答 2

1

您需要向上遍历直到当前元素tbody然后从那里找到下一个元素。您可以使用.closest()向上遍历

$('.fromhere').click(function(){
    $(this).closest('tbody').next('tbody').slideToggle(100)
})

演示:小提琴

于 2013-08-22T13:16:40.047 回答
1

可以试试.parent().next()喜欢

$('.fromhere').parent('tbody').next('tbody').showToggle(100);
于 2013-08-22T13:18:37.427 回答