10 examples of 'classlist toggle' in JavaScript

Every line of 'classlist toggle' 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
28toggleClasses(Toggle, ClassNames) {
29 const Level = ClassNames.indexOf(Toggle);
30 const NewClassNames = ClassNames.slice(0, Level + 1);
31 if (this.removeClasses(NewClassNames)) {
32 NewClassNames.map((Class) => this.renderer.removeClass(this.document.body, Class));
33 }
34 else {
35 this.renderer.addClass(this.document.body, Toggle);
36 }
37}
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

83export function toggle (ident: string, classList: DOMTokenList, toggle: Element, className: string): () => void {
84 let handler = () => {
85 toggleState(ident, classList, className)
86 let event
87 if (typeof Event === 'function') {
88 event = new Event('resize')
89 } else {
90 event = document.createEvent('Event')
91 event.initEvent('resize', true, true)
92 }
93 window.dispatchEvent(event)
94 }
95
96 recoverState(ident, classList, className)
97
98 toggle.addEventListener('click', handler)
99
100 return function () { toggle.removeEventListener('click', handler) }
101}
351export function toggle__class(el, class_name) {
352 return el.classList.toggle(class_name)
353}
41toggleClass(className) {
42 this._node.classList.toggle(className);
43 return this;
44}
196toggleClass(classToToggle) {
197 return Dom.toggleClass(this.el, classToToggle);
198}
34private _toggleClassList(classList: string[]) {
35 let classMap = {};
36 let oldClass = this._oldClass;
37
38 if (oldClass) {
39 oldClass.forEach(name => {
40 if (classList.indexOf(name) === -1) {
41 dom.removeClass(this.element, name);
42 }
43 else {
44 classMap[name] = true;
45 }
46 });
47 }
48
49 classList.forEach(name => {
50 if (!classMap[name]) {
51 dom.addClass(this.element, name);
52 }
53 });
54
55 this._oldClass = classList;
56}
86function toggle(el) {
87 el = document.querySelector(el);
88
89 if (el.style.display === 'none') {
90 el.style.display = 'block';
91 return;
92 }
93
94 el.style.display = 'none';
95}
45function toggle() {
46 var list = document.getElementsByClassName("gwt-TextArea");
47 var button = document.getElementById("hide-console");
48 var console = list[0];
49 if (console.style.display == "block") {
50 console.style.display = "none";
51 console.scrollTop = 99999;
52 button.innerHTML = "show console";
53 } else {
54 console.style.display = "block";
55 console.scrollTop = 99999;
56 button.innerHTML = "hide console";
57 }
58}
181function toggle_class ( selector, name ) {
182 $(selector).toggleClass ( name );
183}
74export function toggleState (ident: string, classList: DOMTokenList, className: string) {
75 // .toggle returns true/false depending if the class is there or not
76 setState(ident, className, classList.toggle(className))
77}

Related snippets