javascript - replace with regex then undo -


i have rather unique problem i'm trying run jquery logic replace text temporarily on page. run logic (i take screenshot tool i'm using). far works great, problem due legacy code need revert changes replace call did on page.

any ideas on best way this? curious, have:

$('body').html($('body').html().replace(/[a-za-z0-9\\*]*@.*\\.com/g,'[replaced screenshot]')) 

thanks!

i'd question motives , reasoning, i'll provided answer nonetheless:

var backup_body_html = $('body').html(); $('body').html(backup_body_html.replace(/[a-za-z0-9\\*]*@.*\\.com/g,'[replaced screenshot]')); 

afterwards:

$('body').html(backup_body_html); 

(unless need keep hold of event handlers etc, in case cloning needed)

cloning method:

var body_children = $("body").clone(true,true).children(); //other stuff (i.e. replacements) //then: $("body").html(""); $("body").append(body_children); 

Comments

Popular posts from this blog

Line ending issue with Mercurial or Visual Studio -

R - Plot: How to format in 10-base scientific notation and put it text, mtex, title etc functions? -

validation - How to pass paramaters like unix into windows batch file -