Get TableHeader Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:TableHeader

Introduction

The TableHeader object represents an HTML <th> element.

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

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
    border: 1px solid black;
}
</style>//  w  w  w .  j a va2 s . c om
</head>
<body>

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

<button onclick="myFunction()">change the text of the TH element</button>

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

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

</body>
</html>

Related Tutorials