Good day. Faced the problem of adding a row to a table. At the moment there is a script:

var mess = document.getElementById("messages"); var div = document.createElement('tr'); div.innerHTML = '<tr> ... </tr>'; mess.appendChild(div); 

Kick, please, in the direction of where to read, and if you feel like it, write how to do it :) Thanks in advance.

  • @Keltis; To format a code, select it with the mouse and click on the {} button of the editor. - zb '
  • messages is table or tbody? why you tr call the variable div? call element at least ... in innerHTML tr, you cannot use the <tr> use <td></td> - zb '
  • this is tbody. - Keltis

1 answer 1

You can for example:

 var mess = document.getElementById("message"); var row = mess.insertRow(-1); var cell = row.insertCell(-1); cell.appendChild(document.createTextNode('Some text message')); 

jsfiddle example