Skip to content

Instantly share code, notes, and snippets.

@maxhoffmann
Last active December 17, 2015 19:49
Show Gist options
  • Select an option

  • Save maxhoffmann/5662924 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown
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