jQuery Replacing Text?

I have the following jQuery code which sort of works but not exactly what I want.  I need to select the table cell that contains the value "Not Reviewed" and wrap it with the Red span.  If the table cell contains just "Reviewed" I want to wrap it with the Green span tag.

It's works but with undesirable results.  "Reviewed" gets colored green in both places. See screenshot.

Undesirable results screenshot.
I'm not that good with jQuery. Please help :)

Here's my code:

<script type="text/javascript">
$(document).ready(function () {
	$("td.ms-gb2:contains('Not Reviewed')").html(function(_, html) {
		return html.replace(/(Not Reviewed)/g, "<span style='color:red'>$1</span>");
	});
	$("td.ms-gb2:contains('Reviewed')").html(function(_, html) {
		return html.replace(/(Reviewed)/g, "<span style='color:green'>$1</span>");
	});
});
</script>

Open in new window

greddinAsked:
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.

Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
quick fix, try change the sequence of scripts.. like:

<script type="text/javascript">

$("td.ms-gb2:contains('Reviewed')").html(function(_, html) {             return html.replace(/(Reviewed)/g, "<span style='color:green'>$1</span>");       }); });

$(document).ready(function () {       $("td.ms-gb2:contains('Not Reviewed')").html(function(_, html) {             return html.replace(/(Not Reviewed)/g, "<span style='color:red'>$1</span>");       });       

</script>
0
greddinAuthor Commented:
Thanks Ryan, I'm having trouble copying and pasting your script.  Code you show in code view how it's suppose to look?
0
greddinAuthor Commented:
Something still isn't right.

Both are green (screenshot)
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
ooops, try this instead:

$("td.ms-gb2:contains('Reviewed'):not(:contains('Not Reviewed'))").html(function (_, html) {
            return html.replace(/(Reviewed)/g, "<span style='color:green'>$1</span>");
        });

        $("td.ms-gb2:contains('Not Reviewed')").html(function (_, html) {
            return html.replace(/(Not Reviewed)/g, "<span style='color:red'>$1</span>");
        });

Open in new window

0

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
greddinAuthor Commented:
Yay! Thank you Ryan. That's it!
0
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.