JS displays the method of the html code for the specified line in the table

  • 2020-05-19 04:17:18
  • OfStack

This example shows how JS displays the html code for a specified row in a table. Share with you for your reference. The details are as follows:

The js code below shows how to get the html code for a specified row, including all the columns, from the rows array of the table


<!DOCTYPE html>
<html>
<head>
<script>
function showRow()
{
alert(document.getElementById('myTable').rows[0].innerHTML);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>Row1 cell1</td>
<td>Row1 cell2</td>
</tr>
<tr>
<td>Row2 cell1</td>
<td>Row2 cell2</td>
</tr>
<tr>
<td>Row3 cell1</td>
<td>Row3 cell2</td>
</tr>
</table>
<br>
<input type="button" onclick="showRow()"
value="Show innerHTML of first row">
</body>
</html>

I hope this article has helped you with your javascript programming.


Related articles: