jQuery to check LI's content - add specific class based on content - trouble with jQuery's $(this)
<p>I'm a jQuery beginner, but I need to style the front-end of a CMS and altering the HTML is not an option, so jQuery to the rescue!  I'll be adding a class to a LI depending on the text inside the LI.</p>

<p>I could use a bit of help using the $(this) object of jQuery. For example the following code works:</p>

<pre><code>if ($('div.nav ul li:nth-child(2):contains("About")').length &gt; 0) {
    $('div.nav ul li:nth-child(2)').addClass("about");
}
</code></pre>

<p>But in order to not repeat my code exponentially, I would rather write something like this:</p>

<pre><code>if ($('div.nav ul li:nth-child(2):contains("About")').length &gt; 0) {
    $(this).addClass("about");
}
</code></pre>

<p>This however is not working.  I'm sure that I'm butchering something terribly obvious, but I've read a few tutorials on the $(this) object and I've been staring at my code long enough to come and ask for a bit of help :)</p>

<p>Also, perhaps I'm missing a much easier solution. Let's say I have the following markup.</p>

<pre><code>&lt;ul id="nav"&gt;
&lt;li&gt;About&lt;/li&gt;
&lt;li&gt;Contact&lt;/li&gt;
&lt;li&gt;News&lt;/li&gt;
&lt;/ul&gt;
</code></pre>

<p>Now let's assume this navigation might change in the future so I can't simply assign a class / icon to each LI using nothing but nth-child.  Is there a way I can loop through each LI, and then loop through each condition?  I'm not familiar enough with jQuery, but in my mix of English and jQuery it might look something like this:</p>

<pre><code>loop through #nav:each li {
    if (child:contains("About")').length &gt; 0) {
        $(this).addClass("about");
    }
    if (child:contains("Contact")').length &gt; 0) {
        $(this).addClass("contact");
    }
    if (child:contains("News")').length &gt; 0) {
        $(this).addClass("news");
    }
}
</code></pre>

<p>Unfortunately that is just made up syntax!  Can anyone possibly help me write that in REAL jQuery :)  If so, I can possibly help you with any CSS issues you may be having.</p>

<p>Thanks!</p>
