I have the following sample HTML:
<tr>
<td>Futebol</td>
<td>Campo</td>
</tr>
<tr>
<td>Volei</td>
<td>Quadra</td>
</tr>
<tr>
<td>Tenis</td>
<td>Saibro</td>
<td>Campo</td>
</tr>
<tr>
<td>Natação</td>
<td>Piscina</td>
</tr>
<tr>
<td>Ciclismo</td>
<td>Rua</td>
</tr>
I would need to loop through tr
by taking the value of each td
and having a json
something like this:
"esportes":[
{
"esporte":"Futebol",
"ambiente":"Campo"
},
{
"esporte":"Volei",
"ambiente":"Quadra"
},
{
"esporte":"Tenis",
"ambiente":"Saibro",
"ambiente":"Campo"
},
{
"esporte":"Ciclimo",
"ambiente":"Rua"
}]
How could I do this with jQuery? I just did this for now but I do not know how to continue from here (if I'm on the way). Turning to JSON is not quite the problem, the biggest problem would be to get the values right, each sport with its usage environment:
$("#tableEsportes > tbody > tr").each(function(){
console.log($(this).text());
});