Is there a way to pass data to an event handler using either EventTarget.dispatchEvent()
or HTMLElement.click()
?
http://jsfiddle.net/yq7yqpL8/1/
var button = document.getElementById('button');
button.addEventListener('foobar', function() {
console.log(arguments); // [Event]
});
button.addEventListener('click', function() {
console.log(arguments); // [MouseEvent]
});
button.click({ foo: 'bar' });
var event = document.createEvent('HTMLEvents');
event.initEvent('foobar', true, false);
button.dispatchEvent(event, { foo: 'bar' });