I have two code examples that use .replace
. One doesn't work and I would like to understand why.
This doesn't work:
var code = document.body.innerHTML;
code=code.replace(/11/g,"22");
code=code.replace(/any/g,"anything");
But, this does:
document.body.innerHTML=document.body.innerHTML.replace(/11/g,"22");
document.body.innerHTML=document.body.innerHTML.replace(/any/g,"anything");