Reputation: 379
Hello everyone I am having the problem of putting array data into the table columns and rows using jquery check my code here http://jsfiddle.net/Reginald/xs5bnz3g/1/ my jquery code is like this
firttd = ["try error catch","Checkers","2015-04-14","2015-04-30"];//wanna
//put this on the table td and tr
var tbody = $('tbody #firstraw'),
var tr = $('<tr>');
$.each(firttd, function(i, prop) {
$('<td>').html(firttd).appendTo(tr);
});
tbody.append(tr);
Upvotes: 0
Views: 108
Reputation: 17366
Few changes and you're done with it
firttd = ["try error catch","Checkers","2015-04-14","2015-04-30"];
var tbody = $('tbody#firstraw'), tr = $('<tr>'); // no need of `var` keyword again after , (comma)
^^^
$.each(firttd, function(i, prop) {
$('<td/>').html(prop).appendTo(tr); // use prop instead of firsttd array
^^^^ ^^^
$('<td/>').appendTo(tr);
});
tbody.append(tr);
And note: You are using $(<td>)
but use $(<td/>)
instead and remove space between $('tbody#firstraw')
Upvotes: 1