A jQuery plugins to substitutes selected strings.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This jQuery plugin will selectively replace strings of text on a page. The search value can be a substring, regular expression or function.


$(selector).substitute(search, replace[, options]);

search string, regular expression or function used to identify strings to substitute. If a string or regular expression is passed, the substitution will be performed using javascript's String.replace() function. If a function is passed it will be called with the following arguments:

  • text The text for the function to act upon.
  • replace The replacement value passed to the jQuery.substitute function. There's no reason this can't be a function if necessary.

replace string or function used for substitution for substrings found by the search parameter.


// Default options exposed so they can be updated globally.
$.fn.substitute.defaults = {
	name: 'substitute',		// A class added to all substituted elements. This can also be used to 'group' substitutions for selective undoing (see below).
	ignoreWhitespace: true	// Change to false to include text nodes which only contain whitespace characters in the substitution. 

Undoing a substitution

$(selector).substitute('undo'[, options]);

There's no reason the selector needs to be the same as when the original substitution was performed. Additionally, the name parameter can be used here to target a specific 'group' of replaced elements.

Feedback, Bug Reports & Contributions

Support requests and bug reports can be posted to the GitHub issue tracker. If you'd like to help improve jQuery.substitute feel free to submit a pull request via GitHub.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.