Finding text and adding class to Parent
Hi,
I want to find some text in an element and if-true, add class1 to it, if not add class2 to it.
eg.
-
<div id="myid">
<p>true</p>
</div>
So I want to search in "div#myid p" for "true" and if found, add class "class1" to the div, otherwise "class2".
Currently I'm using this code:
-
$('td.result').each(function () {
var t = $(this).text();
t = t.replace(/FAIL/, '<span class="fail">FAIL</span>', /PASS/, '<span class="pass">PASS</span>');
$(this).html(t);
});
but its not exactly what I want because I want to add the class to parent.
Thanks in advance for your help.