toggle

The toggle JS DOMTokenList if force is not given, "toggles" token, removing it if it’s present and adding it if it’s not present. If force is true, adds token (same as add()). If force is false, removes token (same as remove()).

Returns true if token is now present; otherwise false.

Throws a "SyntaxError" DOMException if token is empty.

Throws an "InvalidCharacterError" DOMException if token contains any spaces.

Syntax

tokenlist.toggle(token [, force])

Parameters

token

A string.

force

A boolean.

Examples

1 · token · remove

2 · token · add

3 · force · false

4 · force · true

5 · return · false

6 · return · true

add

contains

item

length

remove

replace

supports

value

Web Hypertext Application Technology Working Group (WHATWG)

Home Menu