10 examples of 'angularjs hasclass' in JavaScript

Every line of 'angularjs hasclass' 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
60private static toggleClass(elem: any, elementClassName: string): void {
61 let newClass: string = ' ' + elem.className.replace(/[\t\r\n]/g, ' ') + ' '
62 if (MobileSidebarToggleDirective.hasClass(elem, elementClassName)) {
63 while (newClass.indexOf(' ' + elementClassName + ' ') >= 0) {
64 newClass = newClass.replace(' ' + elementClassName + ' ', ' ')
65 }
66 elem.className = newClass.replace(/^\s+|\s+$/g, '')
67 } else {
68 elem.className += ' ' + elementClassName
69 }
70}
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

612function hasClass($element, targetClass) {
613 var rgx = new RegExp("(?:^|\\s)" + targetClass + "(?!\\S)", "g");
614
615 if ($element.className.match(rgx)) {
616 return true;
617 } else {
618 return false;
619 }
620}
16private static toggleClass(elem: any, elementClassName: string): void {
17 let newClass: string = ' ' + elem.className.replace(/[\t\r\n]/g, ' ') + ' '
18 if (SidebarToggleDirective.hasClass(elem, elementClassName)) {
19 while (newClass.indexOf(' ' + elementClassName + ' ') >= 0) {
20 newClass = newClass.replace(' ' + elementClassName + ' ', ' ')
21 }
22 elem.className = newClass.replace(/^\s+|\s+$/g, '')
23 } else {
24 elem.className += ' ' + elementClassName
25 }
26}
31function hasClass(element, clazz) {
32 return (` ${element.className} `).indexOf(` ${clazz} `) > -1;
33}
72function addCssClass(className) {
73 if (className) {
74 if (isClassListSupported) {
75 panel.classList.add(className);
76 } else {
77 panel.className += ' ' + className;
78 }
79 }
80}
33export function hasClass(el: Element, className: string): boolean {
34 return el.classList.contains(className);
35}
66export function hasClass(element: HTMLElement, className: string): boolean {
67 if (element.classList) {
68 return element.classList.contains(className);
69 } else {
70 return (element.className.split(" ").indexOf(className) >= 0);
71 }
72}
112function hasClass(element, className) {
113 if (element.classList) {
114 return element.classList.contains(className);
115 } else {
116 return (' ' + element.className + ' ').indexOf(' ' + className + ' ') >
117 -1;
118 }
119}
888function hasClass(el, className) {
889 return getClassRegEx(className).test(el.className);
890}
40function hasClass(element, className) {
41 var classes = element.className;
42 return classes && new RegExp("(^| )" + className + "($| )").test(classes);
43}

Related snippets