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
14 lines (13 loc) • 361 B
JavaScript
import isString from 'vanillajs-helpers/isString';
const byId = (id) => document.getElementById(id);
function findById(ids) {
if (isString(ids)) {
return byId(ids);
}
return ids.reduce((nodes, id) => {
const node = byId(id);
node && nodes.push(node);
return nodes;
}, []);
}
export default findById;