Read More Ninja Action!

jQuery Intellisense : Get the $ out!

I came across a little problem today while involves jQuery, Visual Studio 2008, Intellisense, and a monkey.

In short, I was able to solve the problem (except for the monkey which is still attacking) and I thought I would share my findings.

As we all know, JavaScript libraries are currently "the shit" when it comes to UI design. From Prototype to, everyone seems to be jumping on the JavaScript band wagon.

Knowing this, the geniuses over at the jQuery open source project have written their library so that it could safely run alongside other libraries. There are a few ways to do this, but I'm only going to talk about one method which I personally prefer.

Seeing as how everyone just loves to use the dollar sign as the primary entry point, you quickly find these libraries overwrite each other. However, jQuery provides us a simple fix with the "noConflict" method. Thus, loading the jQuery library, then executing "jQuery.noConflict()" removes all jQuery references to "$" and gives them back to the previous owner.

Now, that's cool, but what if I still want to use something short like "$" rather than typing "jQuery" every time? Simple! They have a fix for that too!

<script type='text/javascript' src='jqueryJs.js'></script>
<script type='text/javascript'>
var $j = jQuery.noConflict();
Now, all of your jQuery commands can be accessed using "$j" or whatever else you would like to use. However, that is where the problem with Visual Studio Intellisense pops up.

As you might imagine, Visual Studio 2008 SP1 has no idea what "$j" means. So you lose all of your jQuery intellisense abilities the second you do this. But that's why you're reading this tutorial! I have a hack which will get you right back on track. That was an unintentional rhyme. :P

After following Scott Guthrie's instructions on how to get jQuery intellisense working in Visual Studio 2008, you simply need to take it one step further to include your previous change.

Open the jQuery VS Doc file (I'm working with jquery-1.3.2-vsdoc.js) and look for the following code on line 51:

jQuery = window.jQuery = window.$ = function(selector, context) {
This line identifies the jQuery commands to the IDE. Thus, all you need to do is modify it so that it includes your new command value:

jQuery = window.jQuery = window.$ = window.$j = function(selector, context) {
Once it is saved and visual studio has a chance to repost, you will instantly start seeing the intellisense results following "$j" or whatever command you choose.

Happy Coding!