Skip to content

Instantly share code, notes, and snippets.

Last active Feb 24, 2021
What would you like to do?
A function to test if a JavaScript object is a DOM NodeList. This is designed to work across all browser implementations. StackOverflow question reference
/* Released under the MIT License in 2014. */
function isNodeList(nodes) {
var stringRepr =;
return typeof nodes === 'object' &&
/^\[object (HTMLCollection|NodeList|Object)\]$/.test(stringRepr) &&
nodes.hasOwnProperty('length') &&
(nodes.length === 0 || (typeof nodes[0] === "object" && nodes[0].nodeType > 0));

This comment has been minimized.

Copy link

@julianshapiro julianshapiro commented May 19, 2014

You'll want to change nodes.hasOwnProperty('length') to nodes.length !== undefined for IE8 support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment