0

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);

1 Answer 1

1

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')

Demo

Sign up to request clarification or add additional context in comments.

1 Comment

You can put $('<td>').appendTo(tr); after each td append to align with header label. See this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.