jQuery Find and Replace Characters Loop

By Sam Deering

jQuery code snippet to Find and Replace Characters using a loop of every html element in a web page. Change the values in the replace function to suit your needs.

jQuery('html').each(function(i){ jQuery(this).text(jQuery(this).text().replace('replacetext','withthistext'))})
  • http://workinonit Alex Hoyle

    So to check the contents of a particular element you would replace html with the selector? Whats the purpose of the each? Wouldn’t $(‘selector’).children().each() be better? Anyways, thanks…



Because We Like You
Free Ebooks!

Grab SitePoint's top 10 web dev and design ebooks, completely free!

Get the latest in JavaScript, once a week, for free.