Skip to content

Instantly share code, notes, and snippets.

@yoavweiss
Created December 3, 2015 17:12
Show Gist options
  • Save yoavweiss/2b6a5fdb991be72a1f79 to your computer and use it in GitHub Desktop.
Save yoavweiss/2b6a5fdb991be72a1f79 to your computer and use it in GitHub Desktop.
DOMTokenList feature detection
var tokenListSupports = function(tokenList, token) {
if (!tokenList || !tokenList.supports) {
return false;
}
try {
return tokenList.supports(token);
} catch (e) {
if (e instanceof TypeError) {
console.log("The DOMTokenList doesn't have a supported tokens list");
} else {
console.log("That shouldn't have happened");
}
}
};
var linkSupports = function(token) {
return tokenListSupports(document.createElement("link").relList);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment