-2

I have a tbody, which includes 5 rows(for example), when I tried to count number of rows using the following code I received an error:

var count = $(".grid-row").length
undefined
count
0

Then, I tried ready() and received the following:

$(".grid-row").ready(function() {    console.log( "ready!" );}); 
// ready!

init [prevObject: init(1), context: document, selector: ".grid-row"]

Only When I clicked on 2-5 row in the element's tab in Chrome, I could access all 5 rows:

$(".grid-row").ready(function() {    console.log( "ready!" );});
// VM1565:1 ready!
// init(5) [tr.grid-row.even, tr.grid-row.odd, tr.grid-row.even, tr.grid-row.odd, tr.grid-row.even, prevObject: init(1), context: document, selector: ".grid-row"]

What I should do in this case in order to count all rows? Thanks.

Bucket
  • 7,415
  • 9
  • 35
  • 45

1 Answers1

0

Put your query in document.ready

$( document ).ready(function() {
    var count = $(".grid-row").length
});

Also, make sure the class name is on the TR element and not the TABLE element.

Steven Spungin
  • 27,002
  • 5
  • 88
  • 78