own (string) function via $.fn
I'm a C#.NET developer and in JS/jQuery I missing the...
- "String".Replace("old","new");
...to replace all "old" substrings with a "new" substring inside a string.
jQuery code:
- $(document).ready(function(){
- alert(('Hello [WORLD]. How are you, [WORLD]?').strReplace('[WORLD]','Michael'));
- $.fn.strReplace = function(find,replace) {
- return this.split(find).join(replace);
- }
- }
console output:
[jquery-3.3.1.min.js:2] Uncaught TypeError: "hallo".strReplace is not a function