title: Apply javascript function to an html element
body: <p>Sorry for the noob question but I am trying to apply this javascript function to data in an html table. The function comes from <a href="https://stackoverflow.com/questions/2901102/how-to-print-number-with-commas-as-thousands-separators-in-javascript">this Stack Overflow post</a>.</p>
  
  <pre><code>function numberWithCommas(x) {
      return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  }
  </code></pre>
  
  <p>I wish to apply this function to something like this: </p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;5000&lt;/td&gt;
          &lt;td&gt;5600&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>with the hopes of returning 5,000 next to 5,600.  I can't figure out this simple thing.  I know I need to use an id or class on one of the tags and that this needs to match something in the function so I tried</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr class="numberWithCommas"&gt;
          &lt;td&gt;5000&lt;/td&gt;
          &lt;td&gt;5600&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>to no avail.  I'm sure the function works given the amount of upvotes.</p>
  
  <p>Can a kind soul please walk me through the steps to make this work?  I've googled all over for a basic tutorial and haven't found anything.</p>