How to select the parent elements of child elements containing specific text using jQuery
<p>I've solved my original problem (painfully) but would like to know if there's a better solution (jQuery must have a better way to do this). I'm working with nested tables (SharePoint) and trying to select rows where a child cell contains specific text. I've worked up a simplified example below (and is also on jsFiddle here: <a href="http://jsfiddle.net/tpZyn/6/" rel="nofollow">http://jsfiddle.net/tpZyn/6/</a>)</p>

<p>In this example I'm trying to add the class "red-row" to the rows of cells containing the text "(red)" (keeping in mind that my ultimate goal is to select the desired rows...turning them red is just a way of demonstrating that I've selected them), but all the selectors I've tried end up selecting more than the desired rows. I finally resorted to a filter function that did what I needed to do, but that seems a little awkward. Seems like there should be a better way.</p>

<pre><code>&lt;style&gt;
.red-row {
    background-color: #FF0000;
}
&lt;/style&gt;
&lt;script&gt;
$(document).ready(function () {
    //$('td:contains("(red)")').parent("tr:first").addClass('red-row');
    //$('td&gt;:contains("(red)")').parent().addClass('red-row');
    $('td').filter(function(){var bob = $(this).text().indexOf("(red)"); return (bob &gt; -1 &amp;&amp; bob &lt; 10);}).parent().addClass('red-row');
});
&lt;/script&gt;

    &lt;table&gt;
            &lt;tbody&gt;
                &lt;tr&gt;
                    &lt;td colspan="2"&gt;
                        &lt;h1&gt;My Header&lt;/h1&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
                &lt;tr&gt;
                    &lt;table&gt;
                        &lt;tbody&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                     &lt;h2&gt;Left Column&lt;/h2&gt;

                                &lt;/td&gt;
                                &lt;td&gt;
                                     &lt;h2&gt;Right Column&lt;/h2&gt;

                                &lt;/td&gt;
                            &lt;/tr&gt;
                            &lt;tr&gt;
                                &lt;td&gt;
                                    &lt;table&gt;
                                        &lt;tbody&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(red) Apple&lt;/td&gt;
                                                &lt;td&gt;$3&lt;/td&gt;
                                            &lt;/tr&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(yellow) Banana&lt;/td&gt;
                                                &lt;td&gt;$2&lt;/td&gt;
                                            &lt;/tr&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(yellow) Lemon&lt;/td&gt;
                                                &lt;td&gt;$1&lt;/td&gt;
                                            &lt;/tr&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(red) Cherry&lt;/td&gt;
                                                &lt;td&gt;$2&lt;/td&gt;
                                            &lt;/tr&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(yellow) Quince&lt;/td&gt;
                                                &lt;td&gt;$3&lt;/td&gt;
                                            &lt;/tr&gt;
                                            &lt;tr&gt;
                                                &lt;td&gt;(green) Apple&lt;/td&gt;
                                                &lt;td&gt;$4&lt;/td&gt;
                                            &lt;/tr&gt;
                                        &lt;/tbody&gt;
                                    &lt;/table&gt;
                                &lt;/td&gt;
                                &lt;td&gt;
                                    &lt;p&gt;Some other content&lt;/p&gt;
                                &lt;/td&gt;
                            &lt;/tr&gt;
                        &lt;/tbody&gt;
                    &lt;/table&gt;
                &lt;/tr&gt;
            &lt;/tbody&gt;
        &lt;/table&gt;
</code></pre>
