Introduction:
This article explains 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.Script
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>
<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
<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>
<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>
No comments:
Post a Comment