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
Syntaxvar tokenExists = tokenList.toggle(token, force);
Parameters token
The token to toggle.
force(Optional)
Whether to force adding or removing the token. See Notes.
Return ValueReturns 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.
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 specificationsMicrosoft Developer Network: [Windows Internet Explorer API reference Article]
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