I would like to know how can I handle two events with the same event type. I would like to differentiate both buttons. When I click btn1 I would like to handleEvent and call doSomething1 and when I click btn2 doSomething2.
class MyClass {
constructor() {
const btn1 = document.querySelector('#button1');
const btn2 = document.querySelector('#button2');
btn1.addEventListener('click', this);
btn2.addEventListener('click', this);
}
handleEvent(e) {
if (e.type === 'click') {
this.doSomething1();
this.doSomething2();
}
}
doSomething1() {
console.log('something1');
}
doSomething2() {
console.log('something2');
}
}