What is the correct way to use jQuery combined with "use strict"?

If I have something like the following

"use strict"; $(document).ready(function () { }); 

I get a warning

 '$'is not defined 
+6
source share
2 answers
 ( function ( $ ) { 'use strict'; $( document ).ready( function () { console.log( 'working!' ) }) } ( jQuery ) ) 
+16
source

Have you added jQuery to your site?

Trying the same code on tinker.io throws an error, but then adds jQuery lib, and the error disappears.

CDN: http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js

add it using this snippet

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> 
0
source

Source: https://habr.com/ru/post/913813/


All Articles