Skip to content

Instantly share code, notes, and snippets.

@ryanmorr
Last active January 17, 2024 08:07
Show Gist options
  • Save ryanmorr/71210b81b533eb65843295deae955b2e to your computer and use it in GitHub Desktop.
Save ryanmorr/71210b81b533eb65843295deae955b2e to your computer and use it in GitHub Desktop.
Detect a DOM nodelist or the like
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