javascript - HTML DOM how to optimize this code? -


i got code:

allnodes = document.getelementsbytagname("*"); (node in allnodes) {     if (allnodes[node].innerhtml != undefined) {         allnodes[node].innerhtml = allnodes[node].innerhtml.replace('adshss sd', '1fsss');         allnodes[node].innerhtml = allnodes[node].innerhtml.replace('adsss sd', '1fsss');         allnodes[node].innerhtml = allnodes[node].innerhtml.replace('addsss sd', '1fsss');         allnodes[node].innerhtml = allnodes[node].innerhtml.replace('adfsss sd', '1fsss');     } } 

i have 10 different lines replace text in loop , have noticed takes whole lot of time complete, question is: how can optimize this? goal find text on website (the elements not named of , <td>) , replace it.

i know experiece way quicker if know index number element holding specific text want replace hard find here when there more 200 elements. thanks!

assuming markup doesn't have input value ("adsss sd") attribute value well, try this

since replacing simple text rather markup,

document.body.innerhtml = document.body.innerhtml.replace( /adsss sd/g, '1fsss'); 

Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -