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
Release: 2016-05-16 16:06:51
Original
1221 people have browsed it

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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template