Javascript DOM HTML TableData Object get

Introduction

The TableData object represents an HTML <td> element.

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

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

Click the button to change the text of the first TD element.

View in separate window

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

<table>
 <tr>
   <td id="myTd">Cell 1</td>
   <td>Cell 2</td>
 </tr>
</table>

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

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

<script>
function myFunction() {
  var x = document.getElementById("myTd");
  x.innerHTML = "NEW CELL CONTENT";
}
</script>

</body>
</html>



PreviousNext

Related