Tuesday, 6 August 2013

jQuery - .length of 'table tr' for children of 'this' returning incorrect value

jQuery - .length of 'table tr' for children of 'this' returning incorrect
value

Everything can be found here: http://jsfiddle.net/dweiliu/NBFMq/3/
This is the relevant code in question:
$('article.weeklyStandings').each(function(){
var numPlayers = $(this).children('table tr').length;
$(this).children('h2').append(" - " + numPlayers + " Players");
});
I have potentially multiple tables of data with results as displayed in
the jsfiddle. I want to point out the number of players who played on any
given week by looking up the number of rows in the table.
Why is $(this).children('table tr').length; returning 0 on jsfiddle? Note
that on my local machine, this same code is returning 3.
Any thoughts would help. Thanks!

No comments:

Post a Comment