Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (9.5k points)

 Can anyone tell me how to link a JavaScript file to an HTML document and also how to use jQuery within a JavaScript file? 

1 Answer

0 votes
by (19.7k points)

To use JQuery within the JavaScript file, you need to download the JQuery library from here and load the JQuery library in your HTML head tags like below: 

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<!--LINK JQUERY-->

<script type="text/javascript" src="jquery-3.3.1.js"></script>

<!--PERSONAL SCRIPT JavaScript-->

<script type="text/javascript">

   $(function(){

      alert("My First Jquery Test");

   });

</script>

</head>

<body><!-- Your web--></body>

</html>

If you want to check, you can run your JQuery code after the JQuery loading script. 

To use JQuery scripts separately, define the external .js file like below after the JQuery library loading.

<script type="text/javascript" src="jquery-3.3.1.js"></script>

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

If you want to learn more about Javathen go through this Java tutorial by Intellipaat for more insights. 

Related questions

Browse Categories

...