How to connect jquery to html

Learn how to easily connect jQuery to HTML with a step-by-step example. Master the basics of DOM manipulation and event handling.

Connecting jQuery to HTML is a simple process that allows you to add dynamic functionality to your web pages. Below, I will provide step-by-step instructions on how to link jQuery to your HTML file.

Step 1: Download jQuery

First, you need to download the jQuery library from the official website https://jquery.com/. You can choose to download the compressed production version or the uncompressed development version according to your needs. Once downloaded, save the file in your project directory.

Step 2: Link jQuery to Your HTML File

After downloading jQuery, you need to link it to your HTML file using the <script> tag. Place the following code within the <head> section of your HTML file:

<head>
  <script src="path/to/jquery.js"></script>
</head>

Replace path/to/jquery.js with the actual file path to your downloaded jQuery library.

Step 3: Verify the Connection

To verify that jQuery is successfully linked to your HTML file, you can write a simple jQuery script. Add the following code within the <script> tags at the bottom of your HTML file, just before the closing </body> tag:

<script>
  $(document).ready(function(){
    $("p").click(function(){
      $(this).hide();
    });
  });
</script>

This script will hide the paragraph element when it is clicked. If the paragraph disappears when clicked, it means jQuery is connected and working properly.

By following these three simple steps, you can easily connect jQuery to your HTML file and start leveraging its powerful features to enhance your web pages.

h

Answers (0)