npm-dom / dom-event

Add/remove DOM events
http://npm.im/dom-event
34 stars 7 forks source link

support event delegation (events on child nodes) #1

Open max-mapper opened 10 years ago

max-mapper commented 10 years ago

e.g. if you have a ul full of li elements and you do

dom('ul').on('click', function(el) {
  console.log(el.target)
})

then it should fire for ul and any element that is a descendant of ul

jquery works this way using the same .on syntax by default, e.g. http://jsfiddle.net/YFF2k/2/ (open console and click on some stuff)

there are a number of modules that do this on npm already:

we should probably use dom-delegator cause raynos wrote it :)

the only tricky part is that it would change the default behavior for .on to not only match the element but the element plus all children elements

max-mapper commented 10 years ago

I played with this a bit and I think this one is my favorite https://www.npmjs.org/package/component-delegate

mikkoh commented 9 years ago

I think this issue is somewhat inline with my pull request: https://github.com/npm-dom/dom-event/pull/4