Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
How can I handleEvent two events with the same event type?

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');
    }
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!