title: Change table td using javascript
body: <p>I am new to Javascript so take it easy on me. I want to change data inside a table using javascript. I have looked everywhere for a suitable tutorial but I haven't found any. This is my code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function trans() {
    var table = document.getElementById("table");
    var row = table.getElementsByTagName("tr")[2];
    var td = row.getElementsByTagName("td")[0];
  
    td.innerHTML = "Julius";
  }</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>**css**
  table {
    width: 100%;
    border-collapse: collapse;
    font-family: calibri;
  }
  tr,
  th,
  td {
    border: 2px solid black;
    padding: 10px 10px 10px 10px;
  }
  thead {
    background-color: black;
    color: white;
  }
  tbody {
    background-color: white;
    color: black;
  }
  .center {
    text-align: center;
  }
  .caption {
    text-align: center;
  }
  button {
    background-color: blue;
    color: white;
    border-radius: 5px;
    height: 25px;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
  
  &lt;body&gt;
    &lt;table id="table" title="Employment status verses Living Conditions"&gt;
      &lt;caption&gt;Employment status verses Living Conditions&lt;/caption&gt;
      &lt;thead&gt;
        &lt;tr&gt;
          &lt;th colspan="3" class="caption"&gt;Employment status verses Living Conditions&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;Name&lt;/th&gt;
          &lt;th&gt;State&lt;/th&gt;
          &lt;th&gt;Condition&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tr&gt;
        &lt;td&gt;Antony&lt;/td&gt;
        &lt;td&gt;Employed&lt;/td&gt;
        &lt;td&gt;Poor&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Grace&lt;/td&gt;
        &lt;td&gt;Student&lt;/td&gt;
        &lt;td&gt;Wealthy&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Jane&lt;/td&gt;
        &lt;td&gt;Sponsored&lt;/td&gt;
        &lt;td&gt;Self actualization&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Christine&lt;/td&gt;
        &lt;td colspan="2" class="center"&gt;&lt;i&gt;Unknown&lt;/i&gt;
        &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td rowspan="2"&gt;James and John&lt;/td&gt;
        &lt;td&gt;Fishermen&lt;/td&gt;
        &lt;td&gt;Spiritual&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
        &lt;td&gt;Brothers&lt;/td&gt;
        &lt;td&gt;Disciples&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/table&gt;
    &lt;button onclick="trans()"&gt;Change name&lt;/button&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>When I run the code it gives me the following error, </p>
  
  <pre><code>  {
    "message": "Uncaught TypeError: table.getElementByTagName is not a function",
    "filename": "http://stacksnippets.net/js",
    "lineno": 96,
    "colno": 15
  }
  </code></pre>
  
  <p>I have changed the <code>getElementByTagName</code> to <code>getElementsByTagName</code> but it is still giving me an error, What is wrong with my code and what can I do to fix it. Find my jsfiddle <a href="https://jsfiddle.net/AntonyMN/7m82n4ft/4/" rel="nofollow">here</a></p>