Sunday, May 10, 2009

jQuery Intellisense with VS 2008 SP1 Tips

If you are a poor schlub stuck working on a ASP.NET Webforms project and not an ASP.NET MVC project, you may run into a few hiccups getting the jQuery Intellisense working along the way. Scott Guthrie has a great tutorial, but a couple of important steps are missing. I would like to mention that this is less of an issue with ASP.NET MVC because all of the required files are included in the default project template.



How Did I Get Into This Mess?


You would first go to jquery.com to download the “min” file which is (currently) titled “jquery-1.3.2.min.js”. Following ScottGu’s instructions, you would get the Visual Studio Documentation file linked from his page here and would end up with a documentation file named “jquery-1.3.2-vsdoc2.js”. There are two confusing aspects to this file name:

  1. It has the number “2” at the end of vsdoc
  2. It does not have the “min” section

Does this really matter? No, because all you need to do is match the original jQuery file name and add the text “–vsdoc” before the “.js”, but it adds to a rookies confusion.



The Big Finish


Since you are a pragmatic developer and wish to write unobtrusive javascript, you would create a separate js file and prefix it with this line:


/// <reference path="~/Scripts/jquery-1.3.2.min.js" />

Our new javascript file, the original “jquery-1.3.2.min.js” file, and our newly renamed “jquery-1.3.2.min-vsdoc.js” all reside in a “Scripts” folder. Now we can use jQuery Intellisense to chain the heck out of some methods.

$("#test").addClass('hidden').click();

1 comments:

Rob May 11, 2009 at 7:10 PM  

Dude, you are my new hero