title: How can I add onclick event to a table column?
body: <p>I'm trying to add an <code>onclick</code> event to a table column using JavaScript. For example, an <code>onclick</code> event enabled on the first or second column! The following function is for rows, but I need to edit this function for specific columns.</p>
  <pre><code>function addRowHandlers() {
      var table = document.getElementById(&quot;tableId&quot;);
      var rows = table.getElementsByTagName(&quot;tr&quot;);
      for(i = 0; i &lt; rows.length; i++) {
          var currentRow = table.rows[i];
          var createClickHandler = function (row) {
              return function () {
                  var cell = row.getElementsByTagName(&quot;td&quot;)[0];
                  var id = cell.innerHTML;
                  alert(&quot;id:&quot; + id);
              };
          };
  
          currentRow.onclick = createClickHandler(currentRow);
      }
  }
  </code></pre>