Reputation: 36317
I'm using JS and want to do a string replace of an entire HTML page. I've tried:
var swapIn = 'value="teststring"';
var myOldString = (document.querySelectorAll('html')[0].outerHTML);
var myNewString = myOldString.replace(/value="[^"]*"/g, swapIn);
document = myNewString;
The switch is not occurring, How can I fix this?
Upvotes: 0
Views: 74
Reputation: 8225
you cannot replace document. rather try modifying body innerHTML.
var swapIn = 'value="teststring"';
var myOldString = document.body.innerHTML;
var myNewString = myOldString.replace(/value="[^"]*"/g, swapIn);
document.body.innerHTML = myNewString;
if you are replacing value, I guess you want to change input elements isn't it? A better approach I would suggest would be:
$("input").each(function(){
$(this).val("teststring");
});
Upvotes: 1