Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

87
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda