Get Table Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Table

Introduction

The Table object represents an HTML <table> element.

You can access a <table> element by using getElementById():

Demo Code

ResultView the demo in separate window

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

<table id="myTable">
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>

<button onclick="myFunction()">remove the first row in the table</button>

<script>
function myFunction() {
    var x = document.getElementById("myTable");
    x.deleteRow(0);
}
</script>

</body>
</html>

Related Tutorials