So, what is jQuery anyway?
Why jQuery? Why is it so special?
Key Features of jQuery
- Support for Browser independence: jQuery is supported by most of the modern day browsers.
- Support for a simplified Event Handling model: jQuery provides support for an excellent, easy to use normalized event handling model with much reduced code. The jQuery Event Handling model is consistent across all browsers. The even object is a cross browser normalized one and one event object is always passed as a parameter to an event handler.
- Support for Seamless extensibility: jQuery provides support for extensibility through an easy to use plug-in API that enables extending the jQuery core library seamlessly.
- Visual Studio 2008
- Visual Studio 2008 SP1
- jQuery Library
- Visual Studio 2008 jQuery Plug-in
You can download the jQuery library from this link: http://jquery.com/
As of this writing, the current version of jQuery is 1.3.2
Getting started with jQuery
In this section, we will explore how we can get started with jQuery in ASP.NET in a step-by-step manner.
Note: To get a feel of jQuery intellisense in Visual Studio 2008, you should install the HotFix: KB958502 that comes free from Microsoft. You should also download the jQuery Intellisense file and place it side by side along with the jQuery library in your Visual Studio solution, i.e., place it in the same path.
To get started with your first sample application in ASP.NET that uses jQuery, follow these steps:
1. Open Visual Studio and click on File-> New->Project.
2. Select .NET Framework 3.5 as the version and the ASP.NET Web Application template from the list of templates displayed.
3. Specify a name for the project and click OK to save.
4. Create a new folder in the solution explorer and name it as Scripts.
5. Right-click on this folder and select Add Existing Item.
6. Now, browse to the path where you have downloaded the jQuery library and the jQuery intellisense documentation.
7. Select the two files and click on Add to add the files in the Scripts folder.
8. Next, drag and drop the jquery-1.2.6.js file from the Solution Explorer on to the Head section of the Default.aspx file to create a reference as shown below:
9. Now add the following script to your web page:
The Complete Example
Here is the complete code for your reference:
You can also attach events to your controls using jQuery. The following code example illustrates how you can attach a click event to a hyperlink and displays a message as and when you click on the hyperlink in the browser.
- Learning jQuery (Packt Publishers)
- jQuery Documentation at http://docs.jquery.com/Main_Page
- jQuery in Action (Manning)