Find DOM elements from values in array
<p>I have a potential big list of id's, in this example: "1, 2, 4"</p>

<p>How can I loop through all rows inside a table and add a class to the element inside where the row is being matched with the class from the array? (using jQuery/javascript)</p>

<p>So this table:</p>

<pre><code>&lt;table&gt;
   &lt;tr class="row-1"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;1&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-2"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;2&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-3"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;3&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-4"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;4&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-5"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;5&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
&lt;/table&gt;
</code></pre>

<p>Looks like this afterwards:</p>

<pre><code>&lt;table&gt;
   &lt;tr class="row-1"&gt;
      &lt;td&gt;&lt;span class="foo bar"&gt;1&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-2"&gt;
      &lt;td&gt;&lt;span class="foo bar"&gt;2&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-3"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;3&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-4"&gt;
      &lt;td&gt;&lt;span class="foo bar"&gt;4&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
   &lt;tr class="row-5"&gt;
      &lt;td&gt;&lt;span class="foo"&gt;5&lt;/span&gt;&lt;/td&gt;
   &lt;/tr&gt;
&lt;/table&gt;
</code></pre>