I'm trying to check if an element doesn't contain a specific sentence.
<div id="element">Hey there, This is the element I want to check if it doesn't contain specific text</div>
<script>
var element = document.getElementById('element');
if( element.textContent == 'hello world' < 0 ){
console.log('The element doesn't contain this sentence');
}else{
console.log('The element contain this sentence');
}
</script>
So if the element with id element
doesn't contain hello world
, I if statement should be executed. And if the element contains the text hello world
the else statement should be executed.
This should also work if I check a sentence that does exist like Hey there
, Then the else statement should be executed.