How to get the value (innerHTML) of a cell in HTML table with JavaScript

1 Answer

0 votes
<!DOCTYPE html>
<html>

<head>  
</head>
  
<body>

<table id="table-id" style="border:1px solid green">
<tr><td>abc</td><td>def</td></tr>
<tr><td>ghi</td><td>jkl</td></tr>
</table>


<script>        

function getTableCellValue(id, row, col) 
{
    document.getElementById("p-id").innerHTML = 
                                     document.getElementById(id).rows[row].cells[col].innerHTML;
}

/*
run:
  
def
    
*/

</script>

<button onclick="getTableCellValue('table-id', 0, 1)">Get Table Cell Value</button>

<p id="p-id"></p>

</body>
</html>

 



answered Aug 17, 2015 by avibootz
...