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

122
Vistas
set new value with windows.prevFocus

I have set up previous focus storage in my document. When the button is clicked, a function gets executed. The value 0 is transported as a variable from the button to the function. In the function the new value is set to the previous focussed element. But it doesn't work. Why not? The reason why I do it this way is because I have more buttons, that give different values but only have to use the same function: setNewValue

Main script:

window.prevFocus = $();
// Catch any bubbling focusin events (focus does not bubble)
$(document).on('focusin', ':input', function () {
   // Test: Show the previous value
   $("#debug").html(prevFocus.attr("id"));
   // Save the previously clicked value for later
   window.prevFocus = $(this);
});

Button script

$("#butSetVal0").on({ 
    click: function(){
        newVal = 0;
        setNewValue(newVal);
    }
});

set new value script:

function setNewValue(newVal){
    prevFocus.val(newVal).trigger("input");
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I fixed it already. The solution is to set the eventhandler of the button on 'mousedown'. The 'click' trigger detects two clicks. The second click interprets as the previous focus element, so the button itself.

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