title: jquery datatables - get a td by column name
body: <p>I want to add a class to a td in a specific row. I don't want to fuss with numerical indices, but instead access the td by its column's name. In order words, I'd like to do something like this:</p>
  <pre><code>for each row in the table where the column &quot;role&quot; contains &quot;some text&quot; 
  do add the &quot;red&quot; class to the td in the &quot;email&quot; column.
  </code></pre>
  <p>I've found a way to do it, but I'm not quite satisfied with it; I find it overly complicated. Do someone has something simpler to suggest?</p>
  <p>In the example below, I add the class &quot;red&quot; to the td in the column &quot;email&quot; for every row that has &quot;some text&quot; in the &quot;role&quot; column:</p>
  <pre><code>tab = $(&quot;#myTable&quot;).dataTable({
      &quot;data&quot;: dataset,
      &quot;columns&quot;: [
              { &quot;data&quot;: &quot;uid&quot;, name: &quot;uid&quot; },
              { &quot;data&quot;: &quot;name&quot;, name: &quot;name&quot;},
              { &quot;data&quot;: &quot;role&quot;, name: &quot;role&quot;},
              { &quot;data&quot;: &quot;email&quot;, name: &quot;email&quot;}
      ]               
  });
              
  function GetTdByName(row, column_name) {
          var idx = row.nodes().column(column_name + &quot;:name&quot;)[0]; 
          var selector = &quot;td:eq(&quot; + idx + &quot;)&quot;;
          return row.nodes().to$().find(selector)
  }
      
  $(&quot;#btn&quot;).click(function() {
      var ta = $('#myTable').DataTable();
      ta.rows().every(function () {
              if ($.inArray(this.data().role , [&quot;some text&quot;, &quot;some other text,&quot;] ) &gt; -1) {    
                  GetTdByName(this, &quot;email&quot;).addClass(&quot;red&quot;);
              }
      })
  })              
  </code></pre>
  <hr />
  <h1>Update</h1>
  <p>I've found a neater way to do it. Actually, most of this solution can be found in the official doc: <a href="https://datatables.net/reference/type/column-selector" rel="nofollow noreferrer">column-selector</a></p>
  <pre><code>    ta.rows().every(function () {
          if ($.inArray(this.data().role , [&quot;some text&quot;, &quot;some other text,&quot;] ) &gt; -1) {    
              $(ta.column(&quot;email:name&quot;).nodes()[this.index()]).addClass(&quot;red&quot;);
          }
      })
          
  </code></pre>