10 examples of 'find class name in jquery' in JavaScript

Every line of 'find class name 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
2412function w3AddClass(element, name) {
2413 var i, arr1, arr2;
2414 arr1 = element.className.split(" ");
2415 arr2 = name.split(" ");
2416 for (i = 0; i < arr2.length; i++) {
2417 if (arr1.indexOf(arr2[i]) == -1) {element.className += " " + arr2[i];}
2418 }
2419}
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

14export async function getCssClasses(elementFinder: ElementFinder): Promise<string[]> {
15 const classAttr: string = await elementFinder.getAttribute('class');
16 return classAttr.split(/\s+/);
17}
2421function w3RemoveClass(element, name) {
2422 var i, arr1, arr2;
2423 arr1 = element.className.split(" ");
2424 arr2 = name.split(" ");
2425 for (i = 0; i < arr2.length; i++) {
2426 while (arr1.indexOf(arr2[i]) > -1) {
2427 arr1.splice(arr1.indexOf(arr2[i]), 1);
2428 }
2429 }
2430 element.className = arr1.join(" ");
2431}
50function getClassName(cn) {
51 return CLASSNAMES[cn] || cn;
52}
107function removeClass(elem,cName) {
108 if (elem.className) {
109 var toReplace = elem.className.match(' ' + cName);
110 elem.className = elem.className.replace(toReplace, '');
111 }
112}
12export function addClass(obj: HTMLElement, cls: string) {
13 if (!hasClass(obj, cls)) {
14 obj.className += ` ${cls}`
15 }
16}
45function JQueryClosestByClass(element, clazz) {
46 while (element) {
47 if (JQueryHasClass(element, clazz)) {
48 return element;
49 }
50 element = element.parentNode;
51 }
52 return null;
53}
92function getClassNameName(cn) {
93 if (isClassName(cn)) {
94 return cn[1];
95 } else {
96 throw new Error("Interpreter error: " +
97 "The argument of getClassNameName is not a ClassName value.");
98 }
99}
96function hasClass(el, className) {
97
98 if (!el || !className) {
99 return false;
100 }
101
102 const elClassName = el.className;
103
104 if (!elClassName) {
105 return false;
106 }
107
108 const elClass = elClassName.split(/\s+/);
109
110 return elClass && elClass.findIndex(item => item === className) !== -1;
111
112}
82function hasClass(obj, cl) {
83 return regex(cl).test(obj.className);
84}

Related snippets