JSFiddle - React, Tailwind, and code Playground
HTML
<h2>JavaScript Substring example:</h2>
<div id="myString1">This is some text and i want to find if the work apple is in this string or not!</div>
<br/>
<div id="myString2">This string does not contains that word!</div>
<br/>
<a href="https://code2care.org">Code2care</a>
JavaScript
var val1 = document.getElementById("myString1").innerHTML.indexOf("apple");
var val2 = document.getElementById("myString2").innerHTML.indexOf("apple");
if(val1 > -1) {
console.log("myString1 contains the word apple!");
} else {
console.log("myString1 does not contains the word apple!")
}
if(val2 > -1) {
console.log("myString2 contains the word apple!");
} else {
console.log("myString2 does not contains the word apple!")
}