Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to link jQuery in HTML page?

I have started learning web development, with HTML, jQuery and JavaScript. I want to include jQuery in one of my examples and link it to HTML page. How can I link jQuery if I am having a separate file?


1 Answer
Alex Onsman

To link a separate js file in HTML is quite an easy task. We will see here how to link jQuery in an HTML web page. The linking code comes inside the <head> tag.

Here’s our HTML file, which links to a jQuery file new.js,

<!DOCTYPE html>
<html>
   <head>
      <style>
         div {
          height: 100px;
          width: 100px;
          background-color: red;
          border-radius: 5px;
          border: 2px solid blue;
          margin-left: 50px;
          margin-top: 50px;
          display: none;
         }
      </style>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
      <script src="new.js"></script>
   </head>
   <body>
      <div></div>
   </body>
</html>

Here’s new.js file, with the fadeIn() method, which changes the opacity, for selected elements, from hidden to visible. It is to specify the speed of the fading effect, which can be slow or fast.

$(document).ready(function() {
  $('div').fadeIn('slow');
});
Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.