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
JavaScript
import isString from 'vanillajs-helpers/isString';
import findUniqueNodeCollection from './findUniqueNodeCollection';
const byTag = (elm) => (tag) => elm.getElementsByTagName(tag);
function findByTagName(elm, tagNames) {
if (isString(elm) || Array.isArray(elm)) {
[elm, tagNames] = [document, elm];
}
return findUniqueNodeCollection(tagNames, byTag(elm));
}
export default findByTagName;