4 examples of 'add multiple classes javascript' in JavaScript

Every line of 'add multiple classes javascript' 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
19function addJsClass(el) {
20 var classes = document.body.className.split(" ");
21 classes.push("js");
22 document.body.className = classes.join(" ");
23}
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

96addClassName(className)
97{
98 if (this._classNames.includes(className))
99 return;
100
101 this._classNames.push(className);
102
103 if (this._listItemNode)
104 this._listItemNode.classList.add(className);
105}
395value: function addClasses(classes) {
396 var _this = this;
397
398 classes.forEach(function (className) {
399 _this.element.classList.add(className);
400 });
401}
23public add(...classNames: string[]): void {
24 const attr = this.ownerElement.getAttribute('class');
25 const list = attr ? attr.split(' ') : [];
26 for (const className of classNames) {
27 if (!list.includes(className)) {
28 list.push(className);
29 }
30 }
31 this.ownerElement.setAttribute('class', list.join(' '));
32}

Related snippets