10 examples of 'how to get class name in jquery' in JavaScript

Every line of 'how to get 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
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}
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

9export function getClassName<T>(klass: Function) {
10 return klass.name ? klass.name : /^function\s+([\w\$]+)\s*\(/.exec(this.toString())[1];
11}
50function getClassName(cn) {
51 return CLASSNAMES[cn] || cn;
52}
118function class_name(str) {
119 return str.replace(/[^a-z0-9\s]/gi, '').replace(/[_\s]/g, '-')
120}
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}
3function clzName(name, active) {
4 return (name === active ? 'active' : '');
5}
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}
11function getCssClass(obj) {
12 if (Prototype.Browser.IE) {
13 return obj.className;
14 } else {
15 return obj.getAttribute("class");
16 }
17}
6export function getClassName(elem: Element) {
7 return (elem && elem.getAttribute && elem.getAttribute('class')) || ''
8}
36function getClassName(file) {
37 return file.substr(0, file.lastIndexOf(".js"));
38}

Related snippets