<!DOCTYPE html>
<html>
<head>
<script>
function getValue(){
var cells = document.querySelectorAll('table td');
var data = cells[0].innerHTML;
//alert(cells[0].innerHTML);
document.getElementById("showData").innerHTML += data;
}
</script>
<style>
table, th, td {
border: 1px solid black;
}
table{
}
</style>
</head>
<body>
<h1>How to get value of td element</h1>
<p>Using JavaScript:</p>
<table>
<tr>
<td>Apple</td>
<td>Cell B</td>
</tr>
<tr>
<td>Cell C</td>
<td>Cell D</td>
</tr>
</table>
<br><br>
<h1 id="showData">Result :</h1>
<br>
<button onclick="getValue()">Test</button>
</body>
</html>