JavaScript
Article
By Sam Deering

jQuery Replace All Text On Page

By Sam Deering

Simple jQuery code snippet to replace all the text on the place with any given string. Could be useful for changing company names based on dynamic variables which may change.

Important: don’t forget that the replace() function returns a value and does not do a live update on the page. In order to do this you simply assign the page element with the result of the .replace().

--ADVERTISEMENT--

//ie to replace all dots on page with hyphens
var replace_str = $('body').html().replace(/./g,'-');
$('body').html(replace_str);

//if that doesn't work try this
var strNewString = $('body').html().replace(/./g,'---');
$('body').html(strNewString);
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account