Refael
asked on
jQuery create an array
Hello Experts,
I am trying to create an array : looping on all the rows in a table and garbing each first column text.
Basically this should give an array of numbers e.g. 01, 09, 30 and etc... The below code makes my browser freeze :-))
I am trying to create an array : looping on all the rows in a table and garbing each first column text.
Basically this should give an array of numbers e.g. 01, 09, 30 and etc... The below code makes my browser freeze :-))
$('.table tr').each(function() {
var idArray = [];
var firstTd = $('td:first', $(this));
var firstTdText = firstTd.text();
idArray.push(firstTdText);
});
This works fine:
test it here
<script type='text/javascript'>
$(window).load(function(){
var idArray = [];
$('#myTable tr').each(function () {
var firstTd = $('td:first', $(this));
var firstTdText = firstTd.text();
idArray.push(firstTdText);
});
alert(idArray);
});
</script>
<table id=myTable>
<TR>
<TD>01</TD>
<TD>Test 01</TD>
</TR>
<TR>
<TD>14</TD>
<TD>Test 02</TD>
</TR>
<TR>
<TD>23</TD>
<TD>Test 03</TD>
</TR>
</table>
test it here
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
HainKurt, Alexandre Simões ... Thank you!!!
Open in new window