Monday 21 March 2011

Using JQuery intellisence in visual studio.

Steps to Enable jQuery Intellisense in VS 2008


To enable intellisense completion for jQuery within VS you'll want to follow three steps:

Step 1: Install VS 2008 SP1

VS 2008 SP1 adds richer JavaScript intellisense support to Visual Studio, and adds code completion support for a broad range of JavaScript libraries.

Step 2: Install VS 2008 Patch KB958502 to Support "-vsdoc.js" Intellisense Files

A patch that you can apply to VS 2008 SP1 and VWD 2008 Express SP1 that causes Visual Studio to check for the presence of an optional "-vsdoc.js" file when a JavaScript library is referenced, and if present to use this to drive the JavaScript intellisense engine.

These annotated "-vsdoc.js" files can include XML comments that provide help documentation for JavaScript methods, as well as additional code intellisense hints for dynamic JavaScript signatures that cannot automatically be inferred. You can learn more about this patch here. You can download it for free here.

Step 3: Download the jQuery-vsdoc.js file

Download  jQuery-vsdoc.js file that provides help comments and support for JavaScript intellisense on chained jQuery selector methods. You can download both jQuery and the jQuery-vsdoc file from the official download page on the jQuery.com site:


Save the jquery-vsdoc.js file and your jquery.js file in the same folder of your project (and make sure its naming prefix matches the jquery file name):


You can then reference the standard jquery file with an html <script/> element like so:
<script src="jquery-1.2.6.js" type="text/javascript"></script>

<% if (false) { %> 
 <script src="jquery-1.2.6-vsdoc.js" type="text/javascript"></script>  <% } %>

Or alternatively reference it using the <asp:scriptmanager/> control, or by adding a /// <reference/> comment at the top of a standalone .js file.

For example, we could use jQuery to make a JSON based get request, and get intellisense for the method (hanging off of $.):


Note: Jquery intellisense works in Visual Studio 2010 without any Fix downloading and installing.(i.e, eliminate the step2 from the above steps) and also no need to refer the vs-doc in if else if we write internal scripts for VS2010.

To use jquery intellisense in external JavaScript file

Add the following statement at the top of the external JavaScript file
/// <reference path="jquery-1.2.6-vsdoc.js" />

No comments:

Post a Comment