W3cubDocs

/DOM

DOMTokenList.DOMTokenList.add()

The DOMTokenList.add() method adds one or more DOMString to the list.

Syntax

tokenList.add(token, token2, tokenn);

Example

let node = document.createElement("div"); 
node.classList.add("class1"); 
node.classList.add("class2"); 
node.classList.add("class3"); 

// or with mutliple arguments
node.classList.add("class1", "class2", "class3");

// or with spread syntax
let classList = ["class1", "class2", "class3"];

node.classList.add(...classList);

for(let value of node.classList.values()) { 
  console.log(value); 
} 

The result is:

class1 
class2 
class3

Specifications

Specification Status Comment
DOM
The definition of 'add()' in that specification.
Living Standard Initial definition

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) (Yes) Windows 10, IE 11.608.15063 ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari for iOS Chrome for Andorid Chrome for iOS
Basic support ? (Yes) (Yes) ? ? iOS 10.3.3, Safari 10.0, AppleWebkit 603.3.8 - Yes ? iOS 10.3.3, Chrome 61.0.3163.73 - Yes

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DOMTokenList/DOMTokenList.add()