10 examples of 'replace text jquery' in JavaScript

Every line of 'replace text jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
61function replace( elem, text ) {
62 // dom 3
63 if ( elem.selectionStart >= 0 ) {
64 var start = elem.selectionStart,
65 end = elem.selectionEnd,
66 pos,
67 scrollTop = elem.scrollTop,
68 scrollLeft = elem.scrollLeft;
69
70 elem.value = elem.value.substr(0, start) + text + elem.value.substr(end);
71 pos = start + text.length;
72 elem.selectionStart = pos;
73 elem.selectionEnd = pos;
74 // settings selection selection resets scroll position in FF, so restore it
75 elem.scrollTop = scrollTop;
76 elem.scrollLeft = scrollLeft;
77 // IE
78 } else if ( elem.ownerDocument.selection ) {
79 var range = elem.ownerDocument.selection.createRange();
80 range.text = text;
81 range.move('character', 0);
82 range.select();
83 } else {
84 // browser not supported - set at the end
85 elem.value += text;
86 // scroll to the end of textarea to show inserted
87 elem.scrollTop = 100000;
88 }
89}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

61function replaceText(text) {
62 return text.replace(/\n/g, "").replace(/\s/g, "");
63}
135function getText(text, selector) {
136 if (!selector || !text) return text;
137
138 var id = 0, scripts = {};
139 return $('<div/>').append(
140 text.replace(/<script(.|\s)*?\/script>/g, function (s) {
141 scripts[id] = s;
142 return "jquery-writeCapture-script-placeholder-" + (id++) + '-wc';
143 })
144 ).find(selector).html().replace(PLACEHOLDER, function (all, id) {
145 return scripts[id];
146 });
147 }
50export function _replace(myRange, replacement) {
51 const ctrl = getTextarea()
52 const text = ctrl.value
53 const startText = text.substring(0, myRange.start)
54 ctrl.value =
55 text.substring(0, myRange.start) + replacement + text.substring(myRange.end)
56 setSelection(
57 getSelectionRange(
58 startText.length + replacement.length,
59 startText.length + replacement.length
60 )
61 )
62 return ctrl.value
63}
132export function replaceText(input, options) {
133 return new Replacer(options).replace(input);
134}
35function replaceText(textNode) {
36 var v = textNode.nodeValue;
37
38 // Go through and match/replace all the strings we've given it, using RegExp.
39 for (var i = 0; i < MATCH.length; i++) {
40 v = v.replace(new RegExp('\\b' + MATCH[i] + '\\b', 'g'), REPLACE[i]);
41 }
42
43 textNode.nodeValue = v;
44}
314function replaceText(element, {startIndex, endIndex}, newText) {
315 setSelectionRange(element, startIndex, endIndex);
316
317 d(`Replacing ${getElementText(element).substring(startIndex, endIndex)} with ${newText}`);
318 document.execCommand('insertText', false, newText);
319}
13function simple_text(str) {
14 return str.toLowerCase().replace(/\s+/g, ' ');
15}
173function replaceText(rng, str) {
174 str = me.document.createTextNode(str);
175 rng.deleteContents().insertNode(str);
176}
202function replace(text, replacement) {
203 var varRegex = /\${([^}]+)}/g;
204
205 var self = this;
206 var replacementCache;
207
208 if (typeof replacement === 'string') {
209 if (!self._replacementCache) {
210 self._replacementCache = {};
211 }
212 replacementCache = self._replacementCache;
213 if (!replacementCache[replacement]) {
214 replacementCache[replacement] = replacement.replace(varRegex, function (matches, variable) {
215 var idx;
216
217 idx = self.captures.indexOf(variable);
218 return idx === -1 ? matches : '$' + idx;
219 });
220 }
221 return text.replace(self, replacementCache[replacement]);
222 } else if (typeof replacement === 'function') {
223 return text.replace(self, replacer);
224 }
225 return text;
226
227 function replacer() {
228 var offset, string, json;
229
230 offset = arguments[arguments.length - 2];
231 string = arguments[arguments.length - 1];
232 json = _capturesToJson(self.captures, arguments);
233 return replacement(json, offset, string);
234 }
235}

Related snippets