Skip to content
/ dom Public

simple wrapper of querySelectorAll + addEventListener

License

Notifications You must be signed in to change notification settings

fsubal/dom

Repository files navigation

@fsubal/dom

Simple wrapper of querySelectorAll + addEventListener

dom('.some').find<HTMLInputElement>('.fuga').on('click', e => { ... })

Usage

dom()

Returns dom collection that only provides .on() and .find()

dom.elements

All elements that matched the selector

dom.on()

addEventListener() to all elements that matches the selector

// all .some has now event listeners
dom('.some').on('click', e => { ... })

.on() returns a function that removes event listeners

const off = dom('.some').on('click', e => { ... })

// now all event listeners for click is removed
off()

dom.find()

querySelectorAll() to all elements and create new dom() instance with the flattend one.

※ This method is using Array.prototype.flatMap under the hood. Make sure your supported browsers have it or you should polyfill it.

About

simple wrapper of querySelectorAll + addEventListener

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages