UNPKG

vanillajs-browser-helpers

Version:

Collection of convenience code snippets (helpers) that aims to make it a little easier to work with vanilla JS in the browser

11 lines (10 loc) 408 B
import isString from 'vanillajs-helpers/isString'; import findUniqueNodeCollection from './findUniqueNodeCollection'; const byCn = (elm) => (cn) => elm.getElementsByClassName(cn); function findByClass(elm, classNames) { if (isString(elm) || Array.isArray(elm)) { [elm, classNames] = [document, elm]; } return findUniqueNodeCollection(classNames, byCn(elm)); } export default findByClass;