Reputation: 951
If I have the table:
<table id="mastermind_table_one">
<tr id="one">
<td id='first'>First</td>
<td id='second'>Second</td>
<td id='third'>Third</td>
<td id='forth'>Forth</td>
</tr>
</table>
How would I go about creating an array that contains each td?
I was hoping to get something like:
var array = ["First", "Second", "Third", "Forth"]
Upvotes: 0
Views: 51
Reputation: 206028
var array = [];
$("#one td").text(function(i, txt) { array.push(txt); });
Upvotes: 1
Reputation: 1153
var newArray = [];
$('#one').children().each(function(){
newArray.push($(this).html());
})
Upvotes: 1
Reputation: 104775
Like so:
var array = $("#one td").map(function() {
return $(this).text()
}).get();
Upvotes: 5