10 examples of 'find and replace in jquery' in JavaScript

Every line of 'find and replace in 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
13function findJS(html) {
14 var doc = Slowparse.HTML(document, html).document;
15 return TreeInspectors.findJS(doc);
16}
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

1export function searchAndReplace(str, find, replace) {
2 return str.split(find).join(replace)
3}
14function replace() {
15 var i = 0;
16 var urls = $("[href*='t.co']").length;
17 for (; i < urls; i++) {
18 if ($("[href*='t.co']").eq(i).attr("data-expanded-url") != undefined) {
19 var expanded = $("[href*='t.co']").eq(i).attr("data-expanded-url");
20 } else {
21 var expanded = $("[href*='t.co']").eq(i).attr("title");
22 }
23 $("[href*='t.co']").eq(i).attr("href", expanded);
24 }
25}
55export function find () {
56 return $('.frost-button')
57}
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}
10function findValue(html, regexp) {
11 var r = new RegExp(regexp);
12 var matches=r.exec(html);
13 if(matches==null) return null;
14 return matches[1];
15}
92function replaceAll(target, find, replace) {
93 return target.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
94}
103function replaceAll(string, find, replace){
104 return string.replace(new RegExp(find.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&'), 'g'), replace);
105}
202function replaceAll(target, strToFind, replaceWith, ignoreCase = false) {
203 var flags = "g"; //global match
204 if (ignoreCase === true) {
205 flags += "i";
206 }
207 return target.replace(RegExp(escapeRegExp(strToFind), flags), replaceWith);
208}
212export function replaceAll(target: string, strToFind: string, replaceWith: string, ignoreCase = false): string {
213 var flags = "g"; //global match
214 if (ignoreCase === true) {
215 flags += "i";
216 }
217
218 return target.replace(RegExp(escapeRegExp(strToFind), flags), replaceWith);
219
220}

Related snippets