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.
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.");
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.
var x = document.getElementById("myTable").rows.length;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With