Javascript DOM HTML TableHeader Object get

Introduction

The TableHeader object represents an HTML <th> element.

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

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

Click the button to change the text of the TH element.

View in separate window

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

<table>
 <tr>
   <th id="myTh">Name</th>
 </tr>
 <tr>
   <td>CSS</td>
 </tr>
</table>

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

<p id="demo"></p>

<script>
function myFunction() {
  var x = document.getElementById("myTh");
  x.innerHTML = "New Table Header";
}
</script>

</body>
</html>



PreviousNext

Related