take values from table cells and turn into array
Posted
by liz
on Stack Overflow
See other posts from Stack Overflow
or by liz
Published on 2010-04-10T17:37:43Z
Indexed on
2010/04/10
17:43 UTC
Read the original article
Hit count: 356
using jquery I need to retrieve an array from table cells, format the data and pass it into a js function.
the code i am using is this:
var l1 = new Array();
$('table#datatable tbody td:first-child').each(function() {
l1.push($(this).text());
});
this is the table fragment
<tr>
<th scope="row">Age: 0-4</th>
<td>0</td>
<td>9.7</td>
</tr>
<tr>
<th scope="row">5-17</th>
<td>23.6</td>
<td>18.0</td>
</tr>
<tr>
<th scope="row">Total 0-17</th>
<td>20.6</td>
<td>16.1</td>
</tr>
the table's id is "datatable". i want to return an array of the contents of each first td and then format it like this: 0,23.6,20.6
i am very new to using arrays...
© Stack Overflow or respective owner