jQuery Support in Visual Studio} 

First, I needed to get jQuery. Since my version of Visual Studio doesnt yet understand jQuery, I also needed to get the jQuery support files. Fortunately, theyre both available from one place,  

 
By
Jeff Cogswell  |  Posted 2008-12-12 Email Print this article Print
 
 
 
 
 
 
 


Although I'm talking about IntelliSense here, there probably is curiosity about this code. Like many JavaScript libraries, jQuery recognizes that the document.getElementById() function is probably the single most used function in JavaScript programming, and as such offers a simpler function, one whose name is just the dollar sign, as in $( ).

The parameter to the $ function isn't just the name of an element. Instead, it's a Cascading Style Sheets selector, and as such can be a style class name, an element type or an element name. In CSS, element names are prepended with a pound sign. Since I'm looking for the element named mydiv1, I pass #mydiv1 to the function.

The function doesn't return an HTML object but rather a jQuery object that serves as a proxy to my HTML element. This object includes a method called html() that either returns the inner HTML of the element (when you pass no parameters) or sets the contents (when you pass a string as a parameter). I wanted to set the contents, so I passed a string consisting of the value of the text element. Obtaining the text element's value works similarly, except I called val() instead of html(), and since I wanted to read the value, I passed no parameters.

Easy enough. But when I typed this into Visual Studio, IntelliSense went to work and then understood jQuery. When I type $, a popup appears listing commands, and that one is first. But the whole command is a single character, so I just continued. I typed an open parentheses, and an expanded IntelliSense message displayed.

This message told me the name of the function and the parameters, and additionally described each parameter for me; the message changed as I typed each next parameter. That's just like coding in C#.



 
 
 
 
Jeff Cogswell is the author of Designing Highly Useable Software (http://www.amazon.com/dp/0782143016) among other books and is the owner/operator of CogsMedia Training and Consulting.Currently Jeff is a senior editor with Ziff Davis Enterprise. Prior to joining Ziff, he spent about 15 years as a software engineer, working on Windows and Unix systems, mastering C++, PHP, and ASP.NET development. He has written over a dozen books.
 
 
 
 
 
 
 

Submit a Comment

Loading Comments...
 
Manage your Newsletters: Login   Register My Newsletters























 
 
 
 
 
 
 
 
 
 
 
Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel