Introduction:
Here I will explain how to get number of rows count in table in jQuery or count number of rows in table in jQuery with example or jQuery get number of table rows length or jQuery get rows length in table with example.
Description:
In previous articles I explained jQuery load more records on button click in repeater, jQuery show asp.net exception message in ajax calls, jQuery check whether radiobutton selected or not, jQuery get radio button selected value by name, jQuery validate radiobuttonlist with example, jQuery slideup, slidedown, slidetoggle effects example, jQuery add border to images using css classes and many articles relating to css, AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to use jQuery to get number of rows count in table with example.
In previous articles I explained jQuery load more records on button click in repeater, jQuery show asp.net exception message in ajax calls, jQuery check whether radiobutton selected or not, jQuery get radio button selected value by name, jQuery validate radiobuttonlist with example, jQuery slideup, slidedown, slidetoggle effects example, jQuery add border to images using css classes and many articles relating to css, AngularJS, jQuery, JavaScript and asp.net. Now I will explain how to use jQuery to get number of rows count in table with example.
To get number of rows in table using
jQuery
we need to write the code like as shown below
<script type="text/javascript">
$(function () {
$('#btnGetRows').click(function () {
var rowCount = $('#tblDetails tr').length;
alert(rowCount);
})
});
</script>
|
If you want to check it in complete example you need to write the code like as shown below
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Get Number of
Rows Count in Table</title>
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#btnGetRows').click(function () {
var rowCount = $('#tblDetails tr').length;
alert(rowCount);
})
});
</script>
</head>
<body>
<form id="form1">
<div>
<table id="tblDetails">
<tr>
<th>UserId</th>
<th>UserName</th>
<th>Education</th>
<th>Location</th>
</tr>
<tr>
<td>1</td>
<td>Suresh Dasari</td>
<td>B.Tech</td>
<td>Chennai</td>
</tr>
<tr>
<td>2</td>
<td>Rohini Alavala</td>
<td>Msc</td>
<td>Chennai</td>
</tr>
<tr>
<td>3</td>
<td>Mahendra D</td>
<td>CA</td>
<td>Chennai</td>
</tr>
</table>
<input type="button"
id="btnGetRows"
value="Get
Rows" />
</div>
</form>
</body>
</html>
|
Live
Demo
For live demo try to click on below button to get rows
count. Generally it will return all rows including header row
|
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
0 comments :
Note: Only a member of this blog may post a comment.