DOM Token List

DOM Token List

Introduction

  1. A DOMTokenList is a set of space-separated tokens.
  2. A DOMTokenList can be accessed by index (starts at 0).
  3. The length Property returns the number of tokens in a DOMTokenList.

Note: The classList Property of an HTML element represents a DOMTokenList

  1. In simpler terms it will be a list of CSS classes which are divided by space.

DomTokenList Properties & Methods

  1. add(): The add() method adds one (or more) tokens to a DOMTokenList. Here the tokens are CSS classes
  2. contains(): The contains() method returns true if a DOMTokenList contains a class, otherwise false.
  3. remove(): The remove() method removes one (or more) tokens from a DOMTokenList.
  4. length: The length property returns the number of tokens in a DOMTokenList. The length property is read-only.
  5. values() : The values() method returns an Iterator with the values from a DOMTokenList.