Simple DOM element selection wrapper
$ npm i sdom-js --save
/**
* {String} selector
* {HtmlElement} scope default document
*
* @returns {Array|HtmlElement}
*/
sdom(selector, scope)
Note that if sdom
matches only one element using provided selector, it will return HtmlElement
, otherwise if it matches multiple elements will return Array
of HtmlElements
.
import sdom from 'sdom'
sdom('body') // select document.body
sdom('head') // select document.head
sdom('#id') // select by ID
sdom('.class') // select by class
sdom('div h1') // select by tag name
sdom('[data-attr]') // select by attribute
sdom('meta', head) // changing default scope (document)
sdom('#id', sdom('.el'))
MIT. © 2018 Gardelin