contains
Summary
Tests if a token is part of a DOMTokenList.
Method of dom/DOMTokenListdom/DOMTokenList
Syntax
var tokenExists = tokenList.contains(token);
Parameters
token
- Data-type
- String
The requested token.
Return Value
Returns an object of type BooleanBoolean
Whether the given token exists in the list. Returns true
if the token is present; false
otherwise.
Examples
// check an element's classList (a DOMTokenList) for a specific class
function elHasClass(elid, cls) {
var classes = document.getElementById(elid).classList;
if (classes.contains(cls))
return true;
else
return false;
}
Notes
Throws a SyntaxError
exception if token is empty.
Throws an InvalidCharacterError
exception if token contains any spaces.
Related specifications
- W3C DOM4
- Candidate Recommendation
See also
Related pages
- DOMTokenListDOMTokenList
Attributions
Microsoft Developer Network: [Windows Internet Explorer API reference Article]