9 examples of 'jquery get class name' in JavaScript

Every line of 'jquery get class name' 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

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}
6export function getClassName(elem: Element) {
7 return (elem && elem.getAttribute && elem.getAttribute('class')) || ''
8}
72function $removeClass(el, c) {
73 if (el) el.classList.remove(c);
74}
415function $cls(cls) {
416 return "cls:" + cls;
417}
8function hasClass(elem, className) {
9 return new RegExp(' ' + className + ' ').test(' ' + elem.className + ' ');
10}
82function hasClass(obj, cl) {
83 return regex(cl).test(obj.className);
84}
288Lightbox.prototype._removeClass = function _removeClass(elem, cls) {
289 var regex = new RegExp('\\b' + cls + '\\b');
290 elem.className = elem.className.replace(regex, '')
291}
11function getCssClass(obj) {
12 if (Prototype.Browser.IE) {
13 return obj.className;
14 } else {
15 return obj.getAttribute("class");
16 }
17}

Related snippets