How to use jQuery

If you want to use jQuery then firstly include it on the pages where you wish to take advantage of it. To do this you have to download the jQuery. You can download it from their website at www.jquery.com. After downloading the jQuery JavaScript file, you will have to reference it on your pages using the <script> HTML tag like this:

<script type="text/javascript" src="jquery-1.5.1.js"></script>
Now your page looks something like this:
<head>  
<title>jquery test</title>  
<script type="text/javascript" src="jquery 1.5.1.js"></script>  
</head>
Instead of downloading and hosting jQuery yourself, there is a modern approach. You can include it from CDN (Content Delivery Network).
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>

Example:

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
    $("p").click(function(){  
        $(this).hide();  
    });  
});  
</script>  
</head>  
<body>   
<h1> this is a heading</h1>  
<p>this is a paragraph</p>    
</body>  
</html>
Try Now