How do I loop a check for string in a document in Javascript? -


i'm trying make code search specific text, , if found click button. needs check string continuously, struggling find way happen. i'm complete newb coding, appreciated! :)

var findme = [     //test     'hello!', ];  function findtext() {     var text = document.queryselector('div[id=btntext]');      (var = 0; < findme.length; i++) {         if (btntext.match(findme[i])) {             var btndo = document.queryselector('input[type="submit"][value="click!"]');             if (btndo) {                 btndo.click();             }         }     } } 

just editing code little bit.

i assuming have html this?

<div id="btntext">hello!</div><input type="submit" value="click!"> 

you change code this

var findme = [     //test     'hello!', ];  function findtext() {     var div = document.queryselector('div[id=btntext]');      (var = 0; < findme.length; i++) {         if (div.innertext.indexof(findme[i]) !== -1) {                            var btndo = document.queryselector('input[type="submit"][value="click!"]');             if (btndo) {                 if (typeof btndo.onclick == "function") {                     btndo.onclick.apply(elem);                 }             }             return true;         }     }     return false; } 

if want check continuously. recommend using setinterval.

var interval = setinterval(function() {    var textfound = findtext();    if(textfound) {        clearinterval(interval);    } },50); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -