Last active
January 17, 2024 08:07
-
-
Save ryanmorr/71210b81b533eb65843295deae955b2e to your computer and use it in GitHub Desktop.
Detect a DOM nodelist or the like
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isNodeList(obj) { | |
const type = {}.toString.call(obj).slice(8, -1); | |
switch(type) { | |
case 'NodeList': | |
case 'HTMLCollection': | |
case 'HTMLOptionsCollection': | |
case 'HTMLFormControlsCollection': | |
case 'RadioNodeList': | |
case 'StyleSheetList': | |
return true; | |
default: | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment