How can I check if a div contains a certain word?
var divs= document.getElementsByTagName(\'div\');
for (var i = 0, len = divs.length; i < len; ++i) {
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){}