Javascript DOM HTML TableRow Object get

Introduction

The TableRow object represents an HTML <tr> element.

We can access a <tr> element via document.getElementById():

var x = document.getElementById("myTr");

Click the button to delete the first cell from the table row.

View in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
  border: 1px solid black;
}
</style>/*  ww  w .ja  v  a  2s  .c  o m*/
</head>
<body>

<table>
  <tr id="myRow">
    <td>First cell</td>
    <td>Second cell</td>
    <td>Third cell</td>
  </tr>
</table>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  var row = document.getElementById("myRow");
  row.deleteCell(0);
}
</script>

</body>
</html>



PreviousNext

Related