1
I need to input the data from table html in a array. The current scenario doesn’t allow me to add class
or id
for the tags <td>
(which would make me much easier), later I started the code jquery but I don’t know how to proceed.
HTML
<table id="tb1">
<thead>
<tr>
<th>Bola1</th>
<th>Bola2</th>
<th>Bola3</th>
</tr>
</thead>
<tbody>
<tr><td>3</td><td>10</td><td>5</td></tr>
<tr><td>1</td><td>4</td><td>3</td></tr>
<tr><td>3</td><td>2</td><td>6</td></tr>
</tbody>
</table>
JQUERY
It would be something like this:
$(document).ready(function () {
$('.btnok').on('click', function () {
var dados = [];
var table = $("#tb1 tbody");
table.find("tr").each(function (indice) {
$(this).find('td').each(function (indice) {
dados[indice] = new Object();
dados[indice][indice] = $(this).text();
});
});
});
});
I hope to return a JSON:
[
{"Bola1":"3","Bola2":"10","Bola3":"5"},
{"Bola1":"1","Bola2":"4","Bola3":"3"},
{"Bola1":"3","Bola2":"2","Bola3":"6"}
]
can give an example of the resulting array you expect to have?
– mercador
I changed the post and added an example of what I want to return (JSON)
– hard123