Skip to content

Instantly share code, notes, and snippets.

@0-ali
Last active October 31, 2016 11:19
Show Gist options
  • Save 0-ali/63d5dcb10604cec132e03719b7871855 to your computer and use it in GitHub Desktop.
Save 0-ali/63d5dcb10604cec132e03719b7871855 to your computer and use it in GitHub Desktop.
a jQuery method to replace text
(function ($) {
$.fn.replace = function (a, b) {
this.text(this.text().replace(a, b));
return this.text();
};
})(jQuery);
@0-ali
Copy link
Author

0-ali commented Oct 31, 2016

Definition and Usage

The $.replace() method searches a string for a specified value, or a regular expression, and returns a new string where the specified values are replaced.
This method change the original string.

Syntax

$.replace(searchvalue,newvalue)

Parameter Values

Parameter Description
searchvalue Required. The value, or regular expression, that will be replaced by the new value
newvalue Required. The value to replace the search value with

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment