title: How to access the contents of a cell in HTML table using the cell id?
body: <p>I have created a table in HTML using JavaScript functions insertRow() and insertCell() functions. I have assigned an id for each cell. I would like to get the value/content of the cell in JavaScript.</p>
  
  <p>Following is the code used to create the table:</p>
  
  <pre><code>&lt;HTML&gt;
  &lt;HEAD&gt;
      &lt;SCRIPT language="javascript"&gt;
          function addRow(tableID) {
              var table = document.getElementById(tableID);
              var rowCount = table.rows.length;
  
              var row = table.insertRow(rowCount);
              row.id = rowCount;
  
              var cell1 = row.insertCell(0);
              cell1.id = rowCount + 'a';
              cell1.innerHTML = "CELL1";
  
              var cell2 = row.insertCell(1);
              cell2.id = rowCount + 'b';
              cell2.innerHTML = "CELL2";
  
              var cell3 = row.insertCell(2);
              cell3.id = rowCount + 'c';
              cell3.innerHTML = "CELL3";
  
              var cell4 = row.insertCell(3);
              cell4.id = rowCount + 'd';
              cell4.innerHTML = "CELL4";
          }
       &lt;/SCRIPT&gt;
  &lt;/HEAD&gt;
  &lt;BODY&gt;
  
      &lt;INPUT type="button" value="Add Row" onclick="addRow('dataTable')" /&gt;
  
      &lt;TABLE id="dataTable" width="350px" border="1"&gt;
      &lt;thead&gt;
      &lt;TD&gt;Column 1&lt;/TD&gt;
      &lt;TD&gt;Column 2&lt;/TD&gt;
      &lt;TD&gt;Column 3&lt;/TD&gt;
      &lt;TD&gt;Column 4&lt;/TD&gt;
      &lt;/thead&gt;
      &lt;/TABLE&gt;
  
  &lt;/BODY&gt;
  </code></pre>
  
  <p></p>
  
  <p>I have already tried out the following options:</p>
  
  <ol>
  <li><p>alert(document.getElementById(1a));
  Null</p></li>
  <li><p>alert(document.getElementById(1a).value);
  Error message: Microsoft JScript runtime error: Unable to get value of the property 'value': object is null or undefined</p></li>
  <li><p>alert(document.getElementById("dataTable").rows[rowCount].cells[0]);
  [Object]</p></li>
  <li><p>alert(document.getElementById("dataTable").rows[rowCount].cells[0].toString());
  [Object]</p></li>
  <li><p>alert(document.getElementById("dataTable").rows[rowCount].cells[0].value);
  undefined</p></li>
  </ol>