프로그래밍/스프링[Spring]
[jQuery] 해당 테이블의 tr 개수 구하기
yohoi
2019. 11. 28. 14:43
반응형
이번에는 해당 테이블의 tr 개수를 구하는 방법에 대해 알려드리도록 하겠습니다.
다음과 같이 간단한 예제 코드를 작성합니다.
<table id="myTable" class="table">
<thead>
<tr class="active">
<td class="text-center"><strong>column1</strong></td>
<td class="text-center"><strong>column2</strong></td>
<td class="text-center"><strong>column3</strong></td>
</tr>
</thead>
<tbody id="tbody">
<tr style="font-size: 12px; font-weight: 600;">
<td class="text-center">1</td>
<td class="text-center">내용</td>
<td class="text-center">기타</td>
</tr>
<tr style="font-size: 12px; font-weight: 600;">
<td class="text-center">2</td>
<td class="text-center">내용</td>
<td class="text-center">기타</td>
</tr>
<tr style="font-size: 12px; font-weight: 600;">
<td class="text-center">3</td>
<td class="text-center">내용</td>
<td class="text-center">기타</td>
</tr>
</tbody>
</table>
tr의 개수를 구하는 방법은 간단합니다.
이렇게 작성하시면 해당 테이블의 tbody의 tr 개수를 가져옵니다.
<script>
$('#myTable >tbody tr').length
</script>
감사합니다.
반응형