How to Count Number of Rows in Table JQuery?

By Hardik Savani July 21, 2023 Category : jQuery

Hi Dev,

In this tutorial, i will show you how to get number of rows in table jquery. This post will give you simple example of how to find number of rows in table jquery. i would like to show you how to count number of rows in table using jquery.

if you want to see example of how to find no of rows in a table in jquery then you are a right place. Follow bellow tutorial step of how to get number of rows in html table using jquery.

So, let's see bellow simple solution with example that will help you to getting count numbe r of rows in table using jquery.

Solution:

var trCount = $('#myTable tr').length;

Example:

<!DOCTYPE html>

<html>

<head>

<title>jquery count number of table row - itsolutionstuff.com</title>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

</head>

<body>

<h1>jquery count number of table row - itsolutionstuff.com</h1>

<table id="myTable">

<tr>

<th>ID</th>

<th>Name</th>

</tr>

<tr>

<td>1</td>

<td>Hardik</td>

</tr>

<tr>

<td>2</td>

<td>Vimal</td>

</tr>

<tr>

<td>3</td>

<td>Harshad</td>

</tr>

</table>

<button >Click Me!</button>

<script>

$(document).ready(function(){

$('button').click(function(){

var trCount = $('#myTable tr').length;

alert(trCount);

});

});

</script>

</body>

</html>

I hope it can help you...

Tags :
Shares