Zak The Hat Zak The Hat - 1 year ago 84
jQuery Question

Is it possible to code in jQuery in a JS file? (.js)

Is it possible to code using jQuery in a JS file? (.js) if so, can you please tell me?

Answer Source

Option -1:

Download the jquery file and store it in the directory of the project and add the script tag in your html file and then add second js file which you can write jquery

<script src="jquery.min.js"></script>
<script src="main.js"></script>  //Here you can write your custom js with jquery loaded first

Option -2 :

First take the script file you want to add jquery into and add the following lines of code

var script = document.createElement('script');
script.src = '';
script.type = 'text/javascript';

To test whether jquery actually loaded write this function in main.js file

$(document).ready(function() {
  console.log("Hello Jquery loaded in js file");

Suppose you are using main.js file then write the above 2 code snippets to implement and use the jquery in js file.