10 examples of 'jquery replace class' in JavaScript

Every line of 'jquery replace class' 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
44export function removeClass(element, classname) {
45 if(element && classname) {
46 while(element.className.indexOf(classname) >= 0) {
47 element.className = element.className.replace(classname, '');
48 }
49 }
50};
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

5function removeClass (el, className) {
6 if (el.classList) { el.classList.remove(className) } else { el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ') }
7}
67function removeClass(element, newClassName) {
68 if (element.classList) {
69 element.classList.remove(newClassName);
70 } else {
71 element.className = element.className.replace(new RegExp('(^|\\b)' + newClassName.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
72 }
73}
27export function removeClass(elem, needle) {
28 needle = needle.trim();
29 if (elem.classList) {
30 elem.classList.remove(...needle.split(' '));
31 } else {
32 let elemClass = elem.className.trim();
33 let className = norm(elemClass);
34 needle = SPACE + needle + SPACE;
35 while (className.indexOf(needle) >= 0) {
36 className = className.replace(needle, SPACE);
37 }
38 elem.className = className.trim();
39 }
40}
12function removeClass(element, className) {
13 if (editor.win.hasClass(element, className)) {
14 var classes = element.className.split(" ");
15 for (var i = classes.length - 1 ; i >= 0; i--) {
16 if (classes[i] === className) {
17 classes.splice(i, 1);
18 }
19 }
20 element.className = classes.join(" ");
21 }
22}
18function removeClass(element, className) {
19 if (element.classList) {
20 element.classList.remove(className);
21 } else if (hasClass(element, className)) {
22 var reg = new RegExp('(\\s|^)' + className + '(\\s|$)', 'g');
23 element.className = element.className.replace(reg, ' ');
24 }
25}
72function $removeClass(el, c) {
73 if (el) el.classList.remove(c);
74}
41function domRemoveClass(el, className) {
42 if (el.classList) {
43 el.classList.remove(className);
44 } else {
45 el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
46 }
47}
56export function removeClass(element, className) {
57 if (hasClass(element, className)) {
58 var reg = new RegExp('(\\s|^)' + className + '(\\s|$)');
59 element.className = element.className.replace(reg, ' ');
60 }
61}
122function _removeClass($el, className) {
123 if ($el.$el.classList) {
124 $el.$el.classList.remove(className);
125 } else if ($el.hasClass(className)) {
126 $el.$el.className = (' ' + $el.$el.className + ' ').replace(' ' + className + ' ', ' ');
127 }
128}

Related snippets