selector

DOM selector

DOM selector in functional ES6

Install | Synopsis | Usage | API | Build | Other

Install

npm install selector

Synopsis

Selector is a 30-LOC DOM selector written in functional-style ES6. Use with Browserify, Webpack or jspm.

Usage

import select from "selector"
 
select(".my-class").event("click", function () {
  this.parentNode.classList.toggle("is-expanded");
})
 
select(".my-card-wrap").event("click", function () {
  this.select(".card").toggle("is-flipped")
})
 
select(".my-modal").event("click", function () {
  this.remove("is-visible")
})

select returns an HTMLElement implementing the DOMTokenList interface and the following additional methods:

Simple wrapper for querySelector and querySelectorAll bound to document in the top-most scope, or to the selected HTMLElement in subsequent inner scopes.

Invokes handler for each selected element and bound to the element.

addEventListener wrapper for each selected HTMLElement.

Build

 
git clone https://github.com/bucaran/selector
cd selector
npm install
npm run build

Other

For a more complete solution take a look at qwery.

License

MIT © Jorge Bucaran