A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/dom/DOMTokenList/toggle below:

toggle ยท WebPlatform Docs

toggle Summary

Adds a token to a DOMTokenList if it is not present, or removes it if it is. Returns true if the token is now present (it was added); returns false if it is not (it was removed).

Method of dom/DOMTokenListdom/DOMTokenList

Syntax
var tokenExists = tokenList.toggle(token, force);
Parameters token
Data-type
String

The token to toggle.

force
Data-type
Boolean

(Optional)

Whether to force adding or removing the token. See Notes.

Return Value

Returns an object of type BooleanBoolean

Whether the token exists after the method has executed.

Examples


function elTogItem(elid,itemtog) {
  var classes = document.getElementById(elid).classList;
  return classes.toggle(itemtog);
}



function elTogItemForce(elid,itemtog,force) {
  var classes = document.getElementById(elid).classList;
  return classes.toggle(itemtog,force);
}
Usage
 Throws a SyntaxError  exception if token is empty.

Throws an InvalidCharacterError exception if token contains any spaces.

Notes

If the optional parameter force is not provided, this method removes the token if it is present, or adds the token if it is not present.

If force is true, this method adds the token (functionally equivalent to DOMTokenList.add()). If force is false, this method removes the token (functionally equivalent to DOMTokenList.remove()).

Related specifications
W3C DOM4
Candidate Recommendation
Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4