I think I have a scope problem. This is my html (I know is "bad" html, but it comes as is from another source):
<table>
<tr>
<td>
<div><b>blablabla <span>some text</span></b></div>
</td>
</tr>
<tr>
<td>
<div><b><span>this is another text</span></b></div>
</td>
</tr>
<tr>
<td>
<div><b>blablabla <span>this is</span> <span>one more text</span></b></div>
</td>
</tr>
</table>
and this is my javascript
$(document).ready(function() {
// delete all span in b
$('b span').contents().unwrap();
// delete "blablabla"
$("b:contains('blablabla')").html(function(i, text) {
return text.replace(/blablabla/g, '');
});
$("b").each(function() {
var bcont = $(this).text();
var stxts = [ "this is another text", "this should not match" ];
$.each(stxts, function(i, val) {
alert($("b").text());
if ( bcont == val) {
$(this).closest("tr").css({"background" : "green"});
}
});
});
});
If text inside the b tag matches one of the stxts array values, I want to change the background color of the tr tag containing the b tag that matches. What am I doing wrong? In the if statement condition I've tried the == comparison and the === . Inside the if statement I've tried replacing $(this) with $("b"), with no result. Instead of the $.each I've tried with a for loop with no luck. I'm sure I'm doing it wrong with the "function inside another function" thing. Thanks for your time.