This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

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

Attributions