How to include multiple td into the tr?

I just wanted to append td in the tr

Table

<table class="u-full-width" id="result">
  <thead>
    <tr>
      <th>Project Name</th>
      <th>Id</th>
      <th>Event</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Dave Gamache</td>
      <td>26</td>
      <td>Male</td>
    </tr> 
  </tbody>
</table>

Script

// Receive Message 
socket.on('message', function(data){
  console.log(data);
  var Project = data.project;
  var Id = data.id;
  var Event = data.event;

  var tr = document.createElement("tr");
  var td1 = tr.appendChild(document.createElement('td'));
  var td2 = tr.appendChild(document.createElement('td'));
  var td3 = tr.appendChild(document.createElement('td'));

  td1.innerHTML = Project;
  td2.innerHTML = Id;
  td3.innerHTML = Event;

  document.getElementById("result").appendChild(td1, td2, td3);
});

I come up with this above code but this is not working means see the image…

enter image description here


Source: ajax

Leave a Reply