HTML DOMTokenList remove() Method

Definition and Usage

The remove() method removes one (or more) tokens from the DOMTokenList.

Instance

Example 1

Remove the "myStyle" class from the element:

const list = element.classList;
list.remove("myStyle");

Try It Yourself

Example 2

Add the "myStyle" class to the element:

const list = element.classList;
list.add("myStyle");

Try It Yourself

Example 3

Toggle the open/close of "myStyle":

const list = element.classList;
list.toggle("myStyle");

Try It Yourself

Example 4

Remove multiple classes from the element:

element.classList.remove("myStyle", "anotherClass", "thirdClass");

Try It Yourself

Example 5

Get the number of classes of the element:

let numb = element.classList.length;

Try It Yourself

Example 6

Does the element have the "myStyle" class?

let x = element.classList.contains("myStyle");

Try It Yourself

Example 7

If the element has the "myStyle" class, delete "anotherClass".

if (element.classList.contains("mystyle")) {
  element.classList.remove("anotherClass");
}

Try It Yourself

Syntax

domtokenlist.remove(token, ...)

Parameters

Parameters Description
token Required. The token to be removed from the list.

Return Value

None.

Browser Support

domtokenlist.remove() is a DOM Level 4 (2015) feature.

It is supported by all browsers:

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support

Internet Explorer 11 (and earlier versions) does not support domtokenlist.remove().

Related Pages

length Property

item() Method

add() Method

toggle() Method

forEach() Method

entries() Method

keys() Method

values() Method

DOMTokenList Object