Match a table cell class and index using jQuery
<p>The following code is just a demonstration for the theory that I want to apply to my app so using THIS instead of td.flex is not appropriate for the the second line in the function.</p>

<p>Also I MUST Use .index instead of nth-child for other reasons.</p>

<p>That all said :)</p>

<p>The following function loops through all the TD's in the first row of a table that have a class of flex. For each of these record the index value. The next line is not part of the real application but to test the theory should find all the tds with a class of flex that have an index value that matches the cellIndex value. Any ideas how to get this to work?</p>

<p><strong>Remember this code is to test the theory hence why I am not using nth-child or this to apply the css colouring!</strong></p>

<pre><code>cellIndex = new Array();

    $('table tr:first-child td.flex').each(function (i) {

        cellIndex[i] = $(this).index();

        $($('td.flex').index(cellIndex)).css('background-color', '#ff0000');

    });
</code></pre>

<p>if I do: <code>console.log($('td.flex').index(cellIndex));</code></p>

<p>I get <code>-1</code> for each loop</p>

<p><strong>Just to confirm I know I could do this:</strong></p>

<pre><code>$(this).css('background-color', '#ff0000');
</code></pre>

<p>but this <strong>IS NOT</strong> what I'm trying to achieve with this function and would NOT work in the real application.</p>

<p>HTML example:</p>

<pre><code>&lt;table&gt;
&lt;tr&gt;
&lt;td class="flex"&gt;Flex&lt;/td&gt;
&lt;td&gt;Not Flex&lt;/td&gt;
&lt;td class="flex"&gt;Flex&lt;/td&gt;
&lt;td&gt;Not Flex&lt;/td&gt;
&lt;td&gt;Not Flex&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
</code></pre>
