jQuery の便利な $el.on('click', 'selector', function (e) { のやつ
jQuery, 積極的に使うべきでない派がいるけど以下は便利 $el 中の selector にマッチするときコールバックが実行される
code:javascript
// jQuery の便利なやつ
var $ = jQuery
$('document').on('click', '.foo', (e) => {
// ...
})
もしこれがないとこのような
code:javascript
document.addEventListener('click', (e) => {
if (e.target.className.contains('foo')) {
// ...
}
})
https://gyazo.com/3abe9ba027f7ff46868dbddbd26e6a4c
code:javascript
import {on, off, fire} from 'delegated-events';
// Listen for browser-generated events.
on('click', '.js-button', function(event) {
console.log('clicked', this);
});
// Listen for custom events triggered by your app.
on('robot:singularity', '.js-robot-image', function(event) {
console.log('robot', event.detail.name, this.src);
});
// Dispatch a custom event on an element.
var image = document.querySelector('.js-robot-image');
fire(image, 'robot:singularity', {name: 'Hubot'});