selly
Convenient and optimized DOM element selection.
Install
$ npm i selly --save
Use
// optimizedconst body = // select document.bodyconst head = // select document.head const byID = // select by IDconst byClass = // select by class (returns an Array) const byTag = // select by tag name (returns an Array) // unoptimized (querySelectorAll)const byAttr = // select by attribute (returns an Array) // using a scope element (defaults to document)const meta = // nestedconst scripts =
Note that as of v0.1.0, if only 1 element matches a selector passed to selly
, that element will be returned (instead of an Array containing only 1 item).
const unique = // since only 1 element matched, logs HTMLElement not [HTMLElement]console
License
MIT. © 2017 Michael Cavalea