Skip to content

magicspon/spon-domEvents

Repository files navigation

Install

yarn add @spon/domevents

or

npm install @spon/domevents --save

import domEvents from '@spon/domevents'

const { addEvents, removeEvents } = domEvents(document.body)

addEvents({
	'click [data-toggle-button]': (e, elm) => {
		e.preventDefault()
		elm.classList.toggle('is-active')
	}
})

All events, by default are delegated to the node given to the initial setup. If you want to delegate to a different element, you can pass in a Dom node as the first argument , eg

addEvents(document.querySelector('.my-node'), {
	'click [data-toggle-button]': (e, elm) => {
		e.preventDefault()
		elm.classList.toggle('is-active')
	}
})

About

Tiny wrapper around dom-delegate

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published