Get Table Cell value using Javascript

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I get the text from my cell e..g. <td>Test Text</td>



var elTableCells = elTableRow.getElementsByTagName("td");

alert(elTableCells[0].innerText);
 
You answered your own question. What you're doing below should work, as
long as elTableRow is defined prior to that call. Sample:

<html><body>
<script type="text/javascript">
function test() {
var elTableRow = document.getElementById("somerow");
var elTableCells = elTableRow.getElementsByTagName("td");
alert(elTableCells[0].innerText);
}
</script>
<button onclick="test()">click me</button>
<table>
<tr id="somerow">
<td>cell 1</td>
<td>cell 2</td>
</tr>
</table>
</body>
</html>
 
Hi,
Try this code:
<td id ="tdname">Test Text</td>
alert(document.forms[0].getElementsByTagId("tdname").innerText);
you need to take care of case-sensitivity as javascript is
case-sensitive(that i have not taken care in above code)
Hope this helps
 
Back
Top