I want to get values from a table on my fantasy sports team website using javascript (and ultimately sum them). I also want to properly namespace this for good form and practice.
The following working code attempts to filter out empty rows, leaving me with an array of DOM table rows that I care about.
playerRow = jQuery(".pncPlayerRow");
players = []
var realRows = function(){
playerRow.each(function(){
if (jQuery(this).eq(0).children().eq(7).text() != "--"){
players.push(this);
}
})
return(players); // returns array of non-empty <tr>
}
realRows();
Now, when I try to namespace this, I'm getting a return value of undefined. Here is my code:
FantasyStats = {}
FantasyStats.collect = function(){
var playerRow = jQuery(".pncPlayerRow");
var players = []
var realRows = function(){
playerRow.each(function(){
if (jQuery(this).eq(0).children().eq(7).text() != "--"){
players.push(this);
}
})
return(players);
}
realRows();
}
FantasyStats.collect()
Am I doing this wrong? Any suggestions?