Javascript DOM HTML Table deleteCaption() Method

Introduction

Remove the <caption> element from a table:

document.getElementById("myTable").deleteCaption();

Click the button to remove the caption element from the table.

View in separate window

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

<table id="myTable">
  <caption>This is a table caption</caption>
  <tr>
    <td>cell 1</td>
    <td>cell 2</td>
  </tr>
  <tr>
    <td>cell 3</td>
    <td>cell 4</td>
  </tr>
</table>
<br>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
  document.getElementById("myTable").deleteCaption();
}
</script>

</body>
</html>

The deleteCaption() method removes the first <caption> element from the table.




PreviousNext

Related