The includes() method performs a case-sensitive search and checks if the provided string is contained in the string it was called on.
innerText returns all text contained by an element and all its child elements. innerHtml returns all text, including html tags, that is contained by an element.
use the indexOf function
if(divs[i].innerHTML.indexOf("word") !== -1) {
// something
}
Use includes()
:
node.textContent.includes('Some text');
if (document.getElementById('divId').innerHTML.indexOf("word") != -1) { }
Try the String.indexOf()
function: if (divs[i].text.indexOf('word') != -1) {
You have to use a comparison operator not assign a variable.
if (divs[i].text == '*word*'){
I would recommend to use indexOf
.
if (divs[i].text.indexOf('*word*') != -1){
In addition to what others said about using .indexOf()
function, I'd like to say .text
is not a div node property. User .innerHTML
if (divs[i].innerHTML.indexOf('word') > -1){}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With