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

149
Views
How to use jQuery in global imported functions without jQuery.ready

my code in JS is getting very large right now and so I wanted to outsource sections to other files, for clarity.

In my main file I use

jQuery(document).ready(function ($) {

    $.getScript("/wp-content/plugins/file2.js",function(){
        console.log("loaded 2");
    });
    $.getScript("/wp-content/plugins/file3.js",function(){
        console.log("loaded 3");
    });

This works. In file 2 and 3 I use jQuery with functions like:

function getData(){
$.("#foo").on("click", function(){});
}

So I am getting the error

$ is undefined

because I do not declare $. But if I wrap around the $.ready function I can't access the functions inside file 2 which are used by the other files.

How can I 'declare' the $ separately without loosing the global scope of the function. Or is there even a better way? I only include in html:

<script src="/wp-content/plugins/file1.js" type="text/javascript"></script>

Thanks for helping!

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

0

A copy of jQuery is assigned to $ by default.

It will only be undefined if you:

  • Overwrite it
  • Mask it
  • Call $.noConflict()

… so don't do any of those.

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!