Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the number of rows in a HTML table [duplicate]

I've browsed the Internet looking for an answer on this but I can't find a solution. I want to count the amount of rows my HTML table has in when a link button is pressed. Can someone help me out please?

This is what I have so far:

 $('#HypSelectAll').click(function () {      var count = $('#gvPerformanceResult').children().length;      for (i = 0; i < count; i++) {         alert(i);      }  }); 

But some reason it returns 0 even though I have about 12 rows in my table? I've checked my ID name and it's correct.

like image 270
Code Ratchet Avatar asked Jul 31 '12 14:07

Code Ratchet


People also ask

How do you find duplicates in a table in HTML?

var contents = {}, duplicates = false; $("#yourtableidhere td"). each(function() { var tdContent = $(this). text(); if (contents[tdContent]) { duplicates = true; return false; } contents[tdContent] = true; }); if (duplicates) alert("There were duplicates.");

How can get number of rows in HTML table using jQuery?

Answer: Use the length Property You 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.


1 Answers

var x = document.getElementById("myTable").rows.length; 
like image 113
treeFan Avatar answered Oct 19 '22 15:10

treeFan