Jquery outside html [SOLVED]

Hello campers

Im very new at coding and recently I started using jquery, but I dont want to use it inside of the html. Does anyone knows how I could write the code outside and link it to the html ? Which extension should I use ? And how to link it ?

<script src="newfile.js"></script>

Now you have to create new file called newfile.js in the same folder directory as index.html (make sure index.html has jQuery linked in)

Also make sure you paste this line of code just before you close off your body tag

so
<script src="newfile.js"></script>
</body>

Thanks @michal9909 for helping me. It worked nice. But get another doubt now with your answer. Should I put every <script> including jquery on the bottom of the page ?

Yes, you could do that, this would also be beneficial as it improves the loading speed (barely noticeable). When you do that, make sure that your jQuery link is above all other script links because of course to use jQuery you first need to load it.

In some cases, like when you want to do something before the DOM is loaded you would have to load jQuery in the head.

Ok. Thaks again for the explanation. Let’s get back to code kkkk.

1 Like