What's the proper way to use jQuery in conjunction with 'use strict'?
-
02-06-2021 - |
Domanda
If I have something like the following
"use strict";
$(document).ready(function () {
});
I get the warning
'$'is not defined
Soluzione
( function ( $ ) {
'use strict';
$( document ).ready( function () {
console.log( 'working!' )
})
} ( jQuery ) )
Altri suggerimenti
Did you add jQuery to your site?
Trying the same code on tinker.io produces the error, but then add the jQuery lib and the error goes away.
CDN: http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
add it by using this snippet
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow