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

231
Views
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 answers
Answer question

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 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!