How to Count the Total Number of Rows in an HTML Table Using JavaScript?

Estimated read time 1 min read

You can use the rows property of the table element in JavaScript to get the total number of rows in an HTML table. Here’s an example:

var table = document.getElementById("tableId");
var totalRows = table.rows.length;
console.log("Total Rows: " + totalRows);

In this example, tableId is the id of your HTML table element. The code above gets a reference to the table element using document.getElementById(), and then accesses the rows property of the table to get the number of rows. The total number of rows is logged to the console.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply