jQuery Table How to - Add table cell to table








Question

We would like to know how to add table cell to table.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'
  src='http://code.jquery.com/jquery-1.6.2.js'></script>
<style type='text/css'>
.someclass {<!--  ww w  .  j  a v a 2  s.c  o m-->
  background-color: #f00;
  padding: 5px;
}
</style>
<script type='text/javascript'>
$(function(){
    $('#myid tbody tr').append('<td class="someclass">stuff...</td>');
});
</script>
</head>
<body>
  <table id="myid">
    <tbody>
      <tr>
        <td>Adjacent to added TD</td>
      </tr>
    </tbody>
  </table>
</body>
</html>

The code above is rendered as follows: