10 examples of 'angular hasclass' in JavaScript

Every line of 'angular 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

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}
70private _toggleClass(classes: string, enabled: boolean): void {
71 classes = classes.trim();
72
73 classes.split(/\s+/g).forEach(cls => {
74 if (enabled) {
75 this.renderer.addClass(this.ngEl.nativeElement, cls);
76 } else {
77 this.renderer.removeClass(this.ngEl.nativeElement, cls);
78 }
79 });
80}
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}
164private addClass(classes) {
165 const classArray = (Array.isArray(classes) ? classes : classes.split(' '));
166 classArray.filter((element) => element.length > 0).forEach(element => {
167 this.renderer.addClass(this.el.nativeElement, element );
168 });
169}
72function addCssClass(className) {
73 if (className) {
74 if (isClassListSupported) {
75 panel.classList.add(className);
76 } else {
77 panel.className += ' ' + className;
78 }
79 }
80}
31function hasClass(element, clazz) {
32 return (` ${element.className} `).indexOf(` ${clazz} `) > -1;
33}
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}

Related snippets