Recently I started playing around with jQuery and found it to be really cool. I had used Dojo and mootools a bit before trying jQuery and found I really working with jQuery so far. In order to learn how to work with jQuery I’ve been playing around with several small examples and decided to publish some of them. Mostly for my own reference, but hopefully someone else can find them useful as well.
Installing jQuery and jQuery UI
When I first looked at using jQuery I had a hard time getting my head around what it did exactly. I had used dojo and mootools a bit but not a ton so I was still a noob at using any types of Javascript frameworks. I understand whats going on a little better now but wanted to put up a ‘Getting Started with jQuery’ anyway. Mainly for my own reference but also because I remember trying to get going and wish I could have had some more examples to look at.
When I first looked at using jQuery I had a hard time getting my head around what it did exactly. At that point I had used dojo and mootools a bit but not a ton so I was still a noob at using any types of Javascript frameworks. I understand whats going on a little better now but wanted to put up a ‘Getting Started with jQuery’ anyway. Mainly for my own reference but also because I remember trying to get going and wish I could have had some more examples to look at.
What do I need?
One of the first things that needs to be understood is jQuery is broken up into two major installs. The first one, jQuery is all the core stuff you need to start doing things with jQuery like Selectors, Attributes, Traversing and DOM Manipulation. The other is the User Interface widgets, which contains most of the UI Widgets and cool stuff you see like Accordions, Datepicker, Dialogs, Progressbars, Sliders and Tabs.
In other words you don’t have to have the UI stuff in order to use jQuery but many of the components a web developer commonly needs been developed, tested and are ready to be used in the User Interface install. Below are links to both installs.
There are not many choices for the jQuery download, mainly just whether you want the js files compressed or not. The UI download page lets you choose what widgets you want as well as select from a bunch of different css themes. I took the uncompressed version of jQuery and all the defaults for the UI. I will be using the jQuery 1.3.2/jQuery UI 1.7.2 installs as they are the most up to date as I am writing this.
Let’s write the code
Once you have the both the downloads just unpack them where you want them to go and create a new html page in your application. Then point to three external resources within your html document as follows:
So far you code should look something like this:
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Getting Started with jQuery</title>
<link type=”text/css” href=”css/ui-lightness/jquery-ui-1.7.2.custom.css” rel=”stylesheet” />
<script type=”text/javascript” src=”js/jquery-1.3.2.min.js”></script>
<script type=”text/javascript” src=”js/jquery-ui-1.7.2.custom.min.js”></script>
<script type=”text/javascript”>
$(document).ready(
function()
{
//jQuery code goes here…
}
);
</script>
<style type=”text/css”>
</style>
</head>
<body>
</body>
</html>
Next we are going to add some simple code to make sure it all works. Inside the script tags just add the following.
$(document).ready(
function()
{
$(“#datepicker”).datepicker();
}
);
</script>
Finally, in the body section of the page add this code:
Date: <input id=”datepicker” type=”text”>
</body>
Refresh your page and you should see a text field. If you click inside of it you will see the datepicker control open up. If you see the datepicker control it means both the jQuery core and jQuery UI widgets are installed and working correctly. You can start adding jQuery code to your site at will!












