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

237
Vistas
Jquery keyup event is not triggered outside of document ready function

I wrote the keyup event in an external js file and it's referenced in the html file.

$('input[name=restaurant]').keyup(function(event){
    console.log("keyup");
});

The strange thing is that it won't activate unless I include it in document ready function.

$(document).ready(function(){
    $('input[name=restaurant]').keyup(function(event){
        console.log("keyup");
    });
});

The keyup event worked just fine outside of document ready function before. I don't know what the problem is now.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Because at the time your script ran, the element wasn't in the DOM yet. Thus, $('input[name=restaurant]') doesn't select any element, and no event listener is attached.

$(document).ready() waits for every element in the DOM to finish loading, then executes the callback.

See: Document: DOMContentLoaded event

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