dimanche 8 mars 2015

Selecting content within the current $(this) selector jquery

You can take a look at my jsfiddle for an example of what I am trying to do. Here is the Javascript code in question:



$("#div_games table tr").each(function(index) {
var num = index;
console.log($(this).text());
});


And the table is from Hockey-reference.com.


I want to organize each row (tr) into a csv based pattern. Here is a small example of what the output would look like:



Date,Visitor,G,Home,G
1917-12-19,Toronto Arenas,9,Montreal Wanderers,10


This is how the first two lines of output would look like.


My question is merely about how I can iterate between each tr and then each td within there?


I want to do something that looks like this:



$("#div_games table tr").each(function(index) {
$(this ".td").each(function(index) {
console.log($(this).text + ',');
});
});


I know this code won't work, but is there a way to do something like this? As a side note I am using the node.js based Cheerio, not actually jquery.


Aucun commentaire:

Enregistrer un commentaire