Javascript Ajax jQuery Html PHP Example Quiz New MORE

How to count number of row in a table using jQuery


<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js">
</script>
<style>
table, th, td {
  border: 1px solid black;
  border-collapse: collapse;
}
</style>
<script>
$(document).ready(function(){
  $("button").click(function(){
       var count = $('#myTable tr').length;
       alert("Total Number of row is :"+ count);
  });
});
</script>
</head>
<body>

<p>How to count number of row in a table using jQuery</p>
<button type="button">Show Count</button><br><br>

<table style="width:100%" id="myTable">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
  <tr>
    <td>John</td>
    <td>Doe</td>
    <td>80</td>
  </tr>
</table>


</body>
</html>

Run it yourself