jQuery replaceText: String replace for your jQueries!

Version: 1.1, Last updated: 11/21/2009

Project Homehttp://benalman.com/projects/jquery-replacetext-plugin/
GitHubhttp://github.com/cowboy/jquery-replacetext/
Sourcehttp://github.com/cowboy/jquery-replacetext/raw/master/jquery.ba-replacetext.js
(Minified)http://github.com/cowboy/jquery-replacetext/raw/master/jquery.ba-replacetext.min.js (0.5kb)
Summary
jQuery replaceText: String replace for your jQueries!Version: 1.1, Last updated: 11/21/2009
LicenseCopyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.
ExamplesThis working example, complete with fully commented code, illustrates one way in which this plugin can be used.
Support and TestingInformation about what version or versions of jQuery this plugin has been tested with, and what browsers it has been tested in.
Release History
Functions
jQuery.fn.replaceTextReplace text in specified elements.

License

Copyright © 2009 “Cowboy” Ben Alman, Dual licensed under the MIT and GPL licenses.  http://benalman.com/about/license/

Examples

This working example, complete with fully commented code, illustrates one way in which this plugin can be used.

replaceTexthttp://benalman.com/code/projects/jquery-replacetext/examples/replacetext/

Support and Testing

Information about what version or versions of jQuery this plugin has been tested with, and what browsers it has been tested in.

jQuery Versions1.3.2, 1.4.1
Browsers TestedInternet Explorer 6-8, Firefox 2-3.6, Safari 3-4, Chrome, Opera 9.6-10.1.

Release History

1.1(11/21/2009) Simplified the code and API substantially.
1.0(11/21/2009) Initial release

Functions

jQuery.fn.replaceText

Replace text in specified elements.  Note that only text content will be modified, leaving all tags and attributes untouched.  The new text can be either text or HTML.

Uses the String prototype replace method, full documentation on that method can be found here:

https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Objects/String/Replace

Usage

jQuery('selector').replaceText( search, replace [, text_only ] );

Arguments

search(RegExp|String) A RegExp object or substring to be replaced.  Because the String prototype replace method is used internally, this argument should be specified accordingly.
replace(String|Function) The String that replaces the substring received from the search argument, or a function to be invoked to create the new substring.  Because the String prototype replace method is used internally, this argument should be specified accordingly.
text_only(Boolean) If true, any HTML will be rendered as text.  Defaults to false.

Returns

(jQuery) The initial jQuery collection of elements.

Close