Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Last active December 17, 2015 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxhoffmann/5662924 to your computer and use it in GitHub Desktop.
Save maxhoffmann/5662924 to your computer and use it in GitHub Desktop.
Best parameter hinting for a list of elements?
function toCollection(elementOrString) {
return (elementOrString instanceof Element) ? [elementOrString] :
Array.prototype.slice.call((elementOrString instanceof NodeList) ? elementOrString : document.querySelectorAll(elementOrString));
};
@maxhoffmann
Copy link
Author

It should be possible to pass an element, an array of elements, a nodelist or a string to this function.

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