comparing strings within a jQuery .each loop
<p>I'm trying to add a class to a list item, based on the text content of the item - it's a workaround to highlight items in a dynamically generated menu, but the class gets applied to all the list items. Is it going wrong because I'm comparing two different kinds of variable?</p>

<pre><code>    $(document).ready(function() {  
        $('article[id^=post]').filter(function(){
            var categorySelected = this.className.match(/\bcategory-\w+\b/).toString();
            var trimmed = categorySelected.replace(/^category-/,''); 
            if ( $(this).hasClass(trimmed) ) {
                alert ('article has category = true, location = ' + trimmed );
                    $('div#categories-3 li').each(function(index) {
                        var listItem = $(this).text().toLowerCase().replace(' ','-').toString();
                        if ( listItem = trimmed ) {
                            alert ('listItem = ' + listItem + ' trimmed = ' + trimmed); 
                            $(this).addClass('current-cat'); 
                        };
                    });
            };
        });
    });
</code></pre>

<p>..thanks for the suggestions, have made the change and put more diagnostics in, but still can't make the breakthrough. In this version the 'current-cat' class never gets added:</p>

<pre><code>    $(document).ready(function() {  
        $('article[id^=post]').filter(function(){
            var categorySelected = this.className.match(/\bcategory-\w+\b/).toString();
            var trimmed = categorySelected.replace(/^category-/,''); 
                if ( $(this).hasClass(trimmed) ) {
                    alert ('article has category = true\nlocation = ' + trimmed + '\ntrimmed var is type of ' + (typeof trimmed) );
                        $('.cat-item').each(function(index) {
                            $(this).addClass('item-' + index);
                            var listItem = $(this).text().toLowerCase().replace(' ','-');
                            alert ( 'listItem var is type of ' + typeof listItem ) ;
                            if ( listItem == trimmed ) {
                                 alert ('listItem = ' + listItem + ' trimmed = ' + trimmed); 
                                 $(this).addClass('current-cat'); 
                                 }

                        });
                    };
        });
    });
</code></pre>

<p>here is the HTML it's for:</p>

<pre><code>    &lt;div id="container"&gt;
        &lt;article id="post-49" class="post-49 post type-post status-publish format-standard hentry category-reykjavik reykjavik photograph"&gt;
            some content 
        &lt;/article&gt;
        &lt;div id="categories-3" class="widget widget_categories"&gt;
            &lt;h4 class="widgettitle"&gt;
                Location 
            &lt;/h4&gt;
            &lt;ul&gt;
                &lt;li class="cat-item cat-item-1"&gt;
                    &lt;a href="#"&gt;
                        Havana 
                    &lt;/a&gt;
                &lt;/li&gt;
                &lt;li class="cat-item cat-item-3"&gt;
                    &lt;a href="#"&gt;
                        London 
                    &lt;/a&gt;
                &lt;/li&gt;
                &lt;li class="cat-item cat-item-13"&gt;
                    &lt;a href="#"&gt;
                        Reykjavík 
                    &lt;/a&gt;
                &lt;/li&gt;
            &lt;/ul&gt;
        &lt;/div&gt;
    &lt;/div&gt;
</code></pre>
