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.