This jQuery plugin will selectively replace strings of text on a page. The search value can be a substring, regular expression or function.
Usage
;
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.
Options
// Default options exposed so they can be updated globally.$fnsubstitutedefaults = 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
;
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.
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.