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

82
Views
Problem on using .on(click) inside .on(change)

in this code when i select an option and after that click on button everything is ok but when i select another option and then click on button it first execute for perevius option! then for recent one. how can i fix it? (i need to put my onclick inside onchange function)

$("select").on("change", function (e) {
    let i = 1;
    console.log(this.value);
   
    $("button").click(function () {
      console.log(i++);
    });

  });

output is like this:

option1 1 2 3 4

option2 5 1

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you want it to have only one event handler, you have to remove any previous ones, you can use .off() to remove an event handler.

$("select").on("change", function (e) {
    let i = 1;
    console.log(this.value);
   
    $("button").off('click').click(function () {
        console.log(i++);
    });
});
about 4 years ago · Juan Pablo Isaza Report
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!