I've used the contains()
function successfully, but never have used it with an if-statement
. My below code doesn't seem to work when it should. I am basically saying if H1
contains the word "true", do something, if not do something else. Currently it only shows the first bit of code no matter what is in the 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);
}