How do I change css styles of certain td tags which contain specific text strings, using jQuery?

On my site: http://temp.novelbread.com/informazioni/schiacciatine-biologiche/ you can see a table. I need to be able to do this using jQuery:

For the table cell that contains the word "Grassi" I need to make it's text bold. The HTML for that cell is:
<td class="vc_table_cell" style="text-align:left;"><span class="vc_table_content">Grassi</span></td>

The table is auto-generated so I have to tinker with it using jquery as I can't edit the php code for this.

Any help would be appreciated.
badwolfffAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

badwolfffAuthor Commented:
By the way I managed to get some result using this:

jQuery( "span.vc_table_content:contains('Grassi')" ).css( "text-decoration", "underline" );

but I need it to work only on the td cell which has the exact text string "Grassi"

My rule above applies the css style even to other cells which contain that word (a few tds below) and this is not what I want.

I only need this rule to be applied to ONLY td fields that have that exact and only word.

thanks
badwolfffAuthor Commented:
Sorted it out myself :)

    jQuery("span.vc_table_content").filter(function() {
        return jQuery.trim(jQuery(this).text()) === "Grassi";
    }).css("font-weight", "bold");

Open in new window

Julian HansenCommented:
You might as well let JQuery do some of the work for you by adding the contains selector as well
jQuery( "span.vc_table_content:contains('Grassi')" ).each(function() {
  if (jQuery(this).text() == 'Grassi') {
    jQuery(this).css( "text-decoration", "underline" );
  }
});

Open in new window

Or for your code
   jQuery("span.vc_table_content:contains(Grassi)").filter(function() {
        return jQuery.trim(jQuery(this).text()) === "Grassi";
    }).css("font-weight", "bold");

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

badwolfffAuthor Commented:
I've requested that this question be closed as follows:

Accepted answer: 0 points for badwolfff's comment #a40960394

for the following reason:

I sorted it out myself
badwolfffAuthor Commented:
I am sorry I didn't see your comment there julian as the page had not reloaded.

I managed it myself with this slightly messy code:
    jQuery("span.vc_table_content").filter(function() {
        return jQuery.trim(jQuery(this).text()) === "Grassi" || jQuery.trim(jQuery(this).text()) === "Carboidrati" || jQuery.trim(jQuery(this).text()) === "Fibre" || jQuery.trim(jQuery(this).text()) === "Proteine";
    }).css("font-weight", "bold");

    jQuery("span.vc_table_content").filter(function() {
        return jQuery.trim(jQuery(this).text()) === "di cui:";
    }).css("font-style", "italic");

Open in new window


Can you help me condense it? I am happy for you to have the points in that case :D
Julian HansenCommented:
Not sure about condensing it but I would do it like this
jQuery( "span.vc_table_content" ).each(function() {
    var me = jQuery(this);
    var text = jQuery.trim(me.text());
    if (text == 'Grassi' || 
        text == 'Carboidrati' || 
        text == 'Fibre' || 
        text == 'Proteine') {
      me.css({fontWeight: 'bold'});
    }
    else if (text == 'di cui:') {
      me.css({fontStyle: 'italic'});
    }
});

Open in new window

Note while not incorrect the '===' exact equal operator is not required here is there is not really any ambiguity in the strings.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.