Home >Web Front-end >JS Tutorial >JS method to obtain the html content of the specified cell in the table_javascript skills

JS method to obtain the html content of the specified cell in the table_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:06:511234browse

The example in this article describes the JS method of obtaining the html content of the specified cell in the table. Share it with everyone for your reference. The details are as follows:

The following code first obtains all cell arrays of the specified row through the rows of the table object, then locates the specified cell, and obtains the html content of the cell through the innerHTML attribute of the cell

<!DOCTYPE html>
<html>
<head>
<script>
function cell()
{
var x=document.getElementById('myTable').rows[0].cells;
alert(x[0].innerHTML);
}
</script>
</head>
<body>
<table id="myTable" border="1">
<tr>
<td>cell 1</td>
<td>cell 2</td>
</tr>
<tr>
<td>cell 3</td>
<td>cell 4</td>
</tr>
</table>
<br>
<input type="button" onclick="cell()"
value="Alert first cell">
</body>
</html>

I hope this article will be helpful to everyone’s JavaScript programming design.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn