Adding the jQuery Library to Your Pages

Posted on July 26, 2011

0


The jQuery library is stored as a single JavaScript file, containing all the jQuery methods.

It can be added to a web page with the following mark-up:

<head>
<script type=”text/javascript” src=”jquery.js”></script>
</head>

Please note that the <script> tag should be inside the page’s <head> section.


Basic jQuery Example

The following example demonstrates the jQuery hide() method, hiding all <p> elements in an HTML document.

Example

<html>
<head>
<script type=”text/javascript” src=”jquery.js”></script>
<script type=”text/javascript”>
$(document).ready(function(){
$(“button”).click(function(){
$(“p”).hide();
});
});
</script>
</head><body>
<h2>This is a heading</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Click me</button>
</body>
</html>

Try it yourself »


Downloading jQuery

Two versions of jQuery are available for downloading: one minified and one uncompressed (for debugging or reading).

Both versions can be downloaded from jQuery.com.


Alternatives to Downloading

If you don’t want to store the jQuery library on your own computer, you can use the hosted jQuery library from Google or Microsoft.

Google

<head>
<script type=”text/javascript” src=”http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js”></script&gt;
</head>

Try it yourself »

Microsoft

<head>
<script type=”text/javascript” src=”http://ajax.microsoft.com/ajax/jquery/jquery-1.4.2.min.js”></script&gt;
</head>

Try it yourself »

Advertisements
Posted in: JQuery