C H A P T E R 1
■ ■ ■
3
Introducing jQuery
To fully understand jQuery and its applications in modern web programming, it's
important to take a
moment and look back at where jQuery came from, what needs it was built to fill, and what
programming in JavaScript was like before jQuery came around.
In this chapter you'll learn about JavaScript libraries and the needs they seek to fulfill, as well as why
jQuery is the library of choice for the majority of web developers. You'll also learn the basics of jQuery,
including how to make the library available for use in your applications and how the core of jQuery—its
powerful selector engine—works.
Choosing jQuery over JavaScript
JavaScript has a reputation for being rather unwieldy in web applications. A
lack of consistent browser
support, difficult debugging, and an intimidating syntax can make learning JavaScript feel impossible.
To be fair, all the things that make JavaScript seem difficult are part of what make it so powerful, but
that doesn't make it any more inviting to a novice web developer looking to add JavaScript to his arsenal.
Understanding JavaScript Libraries
The steep learning curve associated with JavaScript has been a sore spot for developers for years, and as
frustrations grew, several ambitious developers started building JavaScript libraries,
also referred to as
JavaScript frameworks.
These libraries aimed to simplify the use of JavaScript to make it more accessible to both new and
existing developers by creating easy-to-use control functions that remove some of the heavy lifting from
everyday JavaScript tasks. Libraries are especially useful in the realm of Asynchronous JavaScript and
XML (AJAX) due to the complexity of performing the same tasks using straight JavaScript.
JavaScript libraries aim to provide a simpler syntax for common tasks, which translates to a faster
workflow for developers and a less intimidating learning curve for beginners. They also eliminate some
of the headache involved in coding cross-browser JavaScript by doing all the
compatibility checks for
you within their built-in methods, which is a
huge time-saver when coding.
www.freepdf-books.com
CHAPTER 1
■
INTRODUCING JQUERY
4
■
Note The difference between using jQuery's AJAX tools versus the straight JavaScript method will be explored
later on in Chapter 2.
A good number of JavaScript libraries are available. Several of the most popular currently in use are
Prototype (
http://www.prototypejs.org), MooTools (
http://mootools.net), Yahoo! UI Library
(
http://developer.yahoo.com/yui), and the focus of this book, jQuery.
Understanding
the Benefits of jQuery
Every JavaScript framework has its own benefits; jQuery is no exception, providing the following
benefits:
• Small file size (approximately 23KB as of version 1.4)
• Extremely simple syntax
• Chainable methods
• Easy plug-in architecture for extending the framework
• A
huge online community
• Great documentation at
http://api.jquery.com
• Optional extensions of jQuery for added functionality, such as jQueryUI
Understanding the History of jQuery
The brain child of developer John Resig jQuery was first announced at BarCamp NYC in early 2006 (for
more on BarCamp, see
http://barcamp.org). Resig noted on his web site, that he created jQuery because
he was unhappy with the currently available libraries and felt that they
could be vastly improved by
reducing “syntactic fluff” and adding specific controls for common actions
(
http://ejohn.org/blog/selectors-in-javascript/).
jQuery was a big hit in the development community and quickly gained momentum. Other
developers came on to help refine the library, ultimately resulting in the first stable release of jQuery,
version 1.0, on August 26, 2006.
Since then, jQuery has progressed to version 1.4.2 (at the time of this writing) and has seen a huge
influx of plug-ins from the development community. A plug-in is an extension of jQuery that isn’t part of
the core library. You'll learn more about (and build) jQuery plug-ins in Chapter 10.
Setting Up a Testing Environment
Because there’s no better way to understand a new language than
to just get your hands dirty, you’ll
need a testing environment to try out some introductory exercises with jQuery. Fortunately, setting up
this testing environment is a simple two-step process: install Firefox, and install Firebug.
www.freepdf-books.com
CHAPTER 1
■
INTRODUCING JQUERY
5
Throughout this book, all exercises will assume that you are using the Firefox browser with the
Firebug plug-in due to its excellent JavaScript testing console.
Installing Firefox
To get Firefox up and running on your computer,
navigate to http://firefox.com and download the
latest version of Firefox (version 3.6 at the time of this writing). After running the installer (
Firefox Setup
Do'stlaringiz bilan baham: