How do I create a table via JavaScript for HTML?
-
I am trying to create a table via js, but everything adds up to one column.
Js code:
$.each(responseJson, function (index, flights) { $("<tr>").appendTo($table) .append($("<td>").text("first")) .append($("<td>").text("second")) .append($("<td>").text("third")) .append($("<td>").text("four")) .append($("<td>").text("five")) });
HTML code:
<table id="tableDiv"> <tr> <th>Взлет</th> <th>Приземление</th> <th>Город</th> <th>Терминал</th> <th>Статус</th> </tr> </table>
JavaScript Anonymous, May 22, 2020 -
- Your table structure is not correct
- backticks `` allow you to split the string into parts. hence you can write html without a thousand append, and use variables without concatenation: $ {tut_peremennaya}
https://codepen.io/5h4dy_s/pen/KKMeZdK?editors=1010Anonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!