如何在具有特定id的表中选择td

How to select the td within a table with a specific id

本文关键字:选择 td id      更新时间:2023-09-26

我遇到了一个问题,我认为有一个非常简单的解决方案,但它难倒了我。在以下代码

  $(document).ready(function() {
    $('#btnHide').click(function() {
        $('td:nth-child(1)').nextUntil(':nth-child(4)').toggle();
    });
});

和html

<table id="tableOne">
<tr>
<td></<td>
</tr>
</table>

我该如何去改变javascript,所以它不针对所有的表,但只是一个与id='tableOne'?

在选择器中添加该表:

$('#tableOne td:nth-child(1)').nextUntil(':nth-child(4)').toggle();