How to get the innerHTML of a cell with JavaScript DOM?

HTMLJavascriptProgramming Scripts

Use the innerHTML property in JavaScript to get the innerHTML of a cell. You can try to run the following code to get the innerHTML of a cell in JavaScript −

Example

Live Demo

<!DOCTYPE html>
<html>
   <head>
      <script>
         function cellFunc(x) {      
            var cell = document.getElementById(x).rows[0].cells;      
            document.write(cell[0].innerHTML);
         }
      </script>
   </head>
   <body>  
      <table style="border:2px solid black" id="newtable">
         <tr>
            <td>One</td>
            <td>Two</td>
         </tr>
         <tr>
            <td>Three</td>
            <td>Four</td>
         </tr>
         <tr>
            <td>Five</td>
            <td>Six</td>
         </tr>
      </table>  
      <p>
         <input type="button" onclick="cellFunc('newtable')" value="Display Table Cell">
      </p>  
   </body>
</html>
raja
Published on 26-Feb-2018 10:20:42
Advertisements