Training Guide: Programming in HTML5 with JavaScript and CSS3 Ebook

(Nora) #1

Lesson 2: Working with jQuery CHAPTER 6 293


txtResult = $('#txtResult');
clear();
}

function clear() {
txtInput.val('0');
txtResult.val('0');
}
After adding the reference, if you type a jQuery expression, you activate IntelliSense as
soon as you enter the dollar sign and the opening parenthesis, as shown in Figure 6-13.

FIGURE 6-13 he jQuery IntelliSense providing help as you typeT

Notice in Figure 6-13 that after you finish typing the selector and you press Period, you are
provided with a valid list of properties and methods for the jQuery wrapper object.
What happens if you are in the clear function and type txtInput and press period? Did
IntelliSense make sense? You get an IntelliSense response that is similar to that in Figure 6-12.
Simply put, don’t activate IntelliSense; txtInput and txtResult are global variables that can be
set to anything anywhere in your application, so Visual Studio can’t possibly provide accurate
IntelliSense. However, if you try typing txtInput and press Period at the bottom of the initial-
ize function, you get proper IntelliSense that’s similar to that in Figure 6-13. The difference is
that Visual Studio is examining your code and knows that you just assigned a jQuery object to
Free download pdf