jQuery in Action

154
CHAPTER 6
jQuery utility functions
Up to this point, we've spent a fair number of chapters examining jQuery com-
mands
--the term that we've applied to methods that operate upon a set of
DOM
ele-
ments wrapped by the
$()
function. But you may recall that way back in chapter 1,
we also introduced the concept of utility functions--functions namespaced by
$
that
don't operate on a wrapped set. These functions could be thought of as top-level
functions except that they are defined on the
$
instance rather than
window
.
Generally, these functions either operate upon JavaScript objects other than
DOM
elements (that's the purview of the commands after all), or they perform
some non-object-related operation.
You may wonder why we waited until this chapter to introduce these functions.
Well, we had two primary reasons, which follow:
We wanted to guide you into thinking in terms of using jQuery commands
rather than resorting to lower-level operations that might feel more famil-
iar but not be as efficient or as easy to code as using the jQuery commands.
Because the commands take care of much of what we want to do when
manipulating
DOM
elements on the pages, these lower-level functions are
frequently most useful when writing the commands themselves (as well as
other extensions) rather than in page-level code. (We'll be tackling how to
write our own plugins to jQuery in the next chapter.)
In this chapter we're finally getting around to formally introducing most of the
$
-level utility functions, as well as a handful of useful flags. We'll put off talking
about the utility functions that deal with Ajax until the chapter that deals exclu-
sively with jQuery's Ajax functionality.
We'll start out with those flags that we mentioned.
6.1 Using the jQuery flags
Some of the information jQuery makes available to us as page authors, and even plu-
gin authors, is available, not via methods or functions but as variables defined on
$
.
These flags are generally focused on helping us divine the capabilities of the current
browser so that we can make decisions based on such information when necessary.
The jQuery flags intended for public use are as follows:
$.browser
$.boxModel
$.styleFloat
Let's start by looking at how jQuery informs us which browser is being used.


Другие страницы

 
Cкачать книги бесплатно без регистрации в электронном виде (pdf, chm, txt).Вы можете читать книги онлайн на нашем сайте литературного портала книг.Большая подборка учебников, пособий, интересных книг.Электронные книги на английском языке скачать бесплатно без смс.