length
PropertyYou can simply use the length
property to count or find the number of rows in an HTML table using jQuery. This property can be used to get the number of elements in any jQuery object.
Let's try out the following example to understand how it actually works:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Get Number of Rows in a Table</title>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var rowCount = $("#myTable tr").length;
alert(rowCount); // Outputs: 4
});
});
</script>
</head>
<body>
<table id="myTable">
<tr>
<th>ID</th>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>1</td>
<td>John</td>
<td>25</td>
</tr>
<tr>
<td>2</td>
<td>Peter</td>
<td>18</td>
</tr>
<tr>
<td>3</td>
<td>Harry</td>
<td>14</td>
</tr>
</table>
<button type="button">Get Number of Rows</button>
</body>
</html>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to Check If a String Contains a Specific Word in PHP
Use the PHP strpos() Function You can...How to get number of elements in a div using jQuery
Use the jQuery .length property You c...Send Verification Mail to New User in Anguler9
Hello folks, In this Angular 7/8/9 Fireb...How to create a string by joining the values of an array in PHP
Use the PHP implode() or ...How to hide dropdown menu on click outside of the element in jQuery
Use the jQuery on() method You can us...