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

842
Views
Is using $ = jQuery; within jQuery( window ).on( 'load', function() { okay?

As $ is undefined in a jQuery( window ).on( 'load', function() { I use $ = jQuery; at the top of this code block and then I can use $ rather than typing jQuery wherever I want to use it like this:

jQuery( window ).on( 'load', function() {

    $ = jQuery;
    var test123 = $( '#test123' );

});

However I have seen on some websites I use this code on it sometimes can throw a Uncaught TypeError: Assignment to constant variable. message occasionally in the console.

Should I be using this method or is there a better alternative to use $ over jQuery

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

0

You can wrap it inside a try-catch.

try{
    window.$ = jQuery;
}catch(e){};
$(window).on('load', function(){
    var test123 = $('#test123');
});
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!