0
I’m a beginner and I would like a help if possible... I have file index.html, which I’m importing the jQuery:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
I want to write the scripts of this page in another file (in my case, index js.). I’m already importing this JS file into my HTML file:
<script src="script/index.js"></script>
That is, I want to use jQuery in this index.js file to interact with index.html.
I used the import $ from 'jquery'
, but it doesn’t work.
I did another test by installing jQuery via NPM and importing into the index.html page, but I can’t import into the index.html page either.
The error that appears in the browser console is:
SyntaxError: import declarations may only appear at top level of a module
How then can I import jQuery into a JS file so that I can develop the interactions of an HTML file?
Read this here https://developer.mozilla.org/en-US/docs/Glossario/Hoisting see if this helps.
– Augusto Vasques
Please [Dit] and provide a [mcve] of the problem to enable the post.
– Bacco