How to add jQuery to your HTML page

Modify your page source

Download jquery and add the relevant version to your site. In the following example it has been deployed to /static/jquery-1.5.2.min.js.

In your html head, add the following:

<script type="text/javascript" src="/static/jquery-1.5.2.min.js"></script>
<script type="text/javascript" language="javascript">
  var $ = jQuery.noConflict();
  $(document).ready(function() {
  function init() {

Now you can refer to $ using the global '$' variable. The init() function is called when the page loads. In this function you can register events on your UI elements and other startup or initialization code.

If you prefer, you can name the $ variable JQ instead.

Published: Monday, 2 May 2011