I have successfully used the contains() function, but have never used it with if-statement . My code below does not work when it should. I basically say that if H1 contains the word "truth," do something, if not do something else. Currently, it only shows the first bit of code no matter what is in H1 .. it never shows the else part.
<H1>This h1 contains the word Star</H1> if ($("H1:contains('True')")) { var test= "<div>IT DID CONTAIN THE WORD TRUE!</div>"; $('h1').append(test); } else { var test= "<div>IT DID <b>NOT</b> CONTAIN THE WORD TRUE!</div>"; $('h1').append(test); }
Toddn source share