public
Created

  • Download Gist
on.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
var stop = eventTarget.on("event", function optionalFilter(event) {
return event.target.classList.contains("some-class")
}, function listener(event) {
// handle event
})
 
// stop listening()
stop()
 
// sugar
 
function matchesSelector(selector) {
return function (event) {
return event.target.matchesSelector(selector)
}
}
 
eventTarget.on("event", matchesSelector(".some-class"), listener)

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.