I have this error when executing my html page, I have a normal html
<HTML>
<HEAD>
<script type="text/javascript" src="js/d3.v3.min.js"></script>
<script type="text/javascript" src="js/utilities.js"></script>
<script src="https://code.jquery.com/jquery-3.3.1.js"></script>
<TITLE>Título de la página</TITLE>
</HEAD>
<BODY>
Aquí iría el contenido de la página
</BODY>
</HTML>
but when executing my page it shows me an error in the file "utilerias.js" contains the following:
$(document).ready(function() {
$(document).on('click','#id_articulo', function(e) {
e.preventDefault();
alert('CLICK');
return false;
});
});
The error is marked in the first line $(document..... Help, please, I have already tried several solutions and the error continues.
The call to your scripts is incorrect, at the moment you have it like this
The problem is that when the browser executes the code of
utilities.js
the call to JQUERY it still does not occur, so it does not recognize the syntax of$
so it should be like thisGiven the above, by the time the code is executed,
utilities.js
the browser already knows the syntax of the JQUERY library.You should put the scripts at the end of your page just before
</body>
because the scripts in the head will block the rendering of your pageHTML
until they are fully downloaded.The error you have is that your libraries
j3
andutilities
are dependent onJQuery
and each script when fully downloaded is executed and continues downloading the following scripts, you can adjust the order so thatJQuery
it is the first to be called like this when the other two libraries are executedJQuery
already available.If you want to use the scripts in it you can use the or
head
attributes , depending on your use case, so that the rendering of your HTML is not blocked.async
defer
And even if you use
async
ordefer
, the execution order of each script must always be taken into account.