jQuery in Action

14
CHAPTER 1
Introducing jQuery
1.3.6 Using jQuery with other libraries
Even though jQuery provides a set of powerful tools that will meet the majority of
the needs for most page authors, there may be times when a page requires that
multiple JavaScript libraries be employed. This situation could come about
because we're in the process of transitioning an application from a previously
employed library to jQuery, or we might want to use both jQuery and another
library on our pages.
The jQuery team, clearly revealing their focus on meeting the needs of their
user community rather than any desire to lock out other libraries, have made pro-
visions for allowing such cohabitation of other libraries with jQuery on our pages.
First, they've followed best-practice guidelines and have avoided polluting the
global namespace with a slew of identifiers that might interfere with not only
other libraries, but also names that you might want to use on the page. The iden-
tifiers
jQuery
and its alias
$
are the limit of jQuery's incursion into the global
namespace. Defining the utility functions that we referred to in section 1.3.2 as
part of the
jQuery
namespace is a good example of the care taken in this regard.
Although it's unlikely that any other library would have a good reason to
define a global identifier named
jQuery
, there's that convenient but, in this par-
ticular case, pesky
$
alias. Other JavaScript libraries, most notably the popular
Prototype library, use the
$
name for their own purposes. And because the usage
of the
$
name in that library is key to its operation, this creates a serious conflict.
The thoughtful jQuery authors have provided a means to remove this conflict
with a utility function appropriately named
noConflict()
. Anytime after the con-
flicting libraries have been loaded, a call to
jQuery.noConflict();
will revert the meaning of
$
to that defined by the non-jQuery library.
We'll further cover the nuances of using this utility function in section 7.2.
1.4 Summary
In this whirlwind introduction to jQuery we've covered a great deal of material in
preparation for diving into using jQuery to quickly and easily enable Rich Inter-
net Application development.
jQuery is generally useful for any page that needs to perform anything but the
most trivial of JavaScript operations, but is also strongly focused on enabling
page authors to employ the concept of Unobtrusive JavaScript within their pages.
With this approach, behavior is separated from structure in the same way that
CSS


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

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