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

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

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