How do I put a jQuery code in an external .js file?

Create an external JavaScript file and add the jQuery code in it.


Let’s say the name of the external file is demo.js. To add it in the HTML page, include it like the following −

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


Above we added jQuery using Google CDN and the external file was included after that.
Add jQuery code in demo.js, since you wanted to place jQuery code −



Updated on: 20-Feb-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started