- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I put a jQuery code in an external .js file?
Create an external JavaScript file and add the jQuery code in it.
Example
Let’s say the name of the external file is demo.js. To add it in the HTML page, include it like the following −
<html> <head> <script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script src="demo.js"></script> </head> <body> <h1>Hello</h1> </body> </html>
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 −
$(document).ready(function(){ alert(“amit”) });
Advertisements