Developing with jQuery in Microsoft Visual Studio 2008 - Page 4

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#.