jQuery in Action

2
CHAPTER 1
Introducing jQuery
Considered a "toy" language by serious web developers for most of its lifetime, Java-
Script has regained its prestige in the past few years as a result of the renewed
interest in Rich Internet Applications and Ajax technologies. The language has
been forced to grow up quickly as client-side developers have tossed aside cut-and-
paste JavaScript for the convenience of full-featured JavaScript libraries that solve
difficult cross-browser problems once and for all and provide new and improved
paradigms for web development.
A relative latecomer to this world of JavaScript libraries, jQuery has taken the
web development community by storm, quickly winning the support of major
websites such as
MSNBC
, and well-regarded open source projects including
SourceForge, Trac, and Drupal.
Compared with other toolkits that focus heavily on clever JavaScript tech-
niques, jQuery aims to change the way that web developers think about creating
rich functionality in their pages. Rather than spending time juggling the complex-
ities of advanced JavaScript, designers can leverage their existing knowledge of
Cascading Style Sheets (
CSS
), Extensible Hypertext Markup Language (
XHTML
),
and good old straightforward JavaScript to manipulate page elements directly,
making more rapid development a reality.
In this book, we're going to take an in-depth look at what jQuery has to offer
us as page authors of Rich Internet Applications. Let's start by finding out what
exactly jQuery brings to the page-development party.
1.1 Why jQuery?
If you've spent any time at all trying to add dynamic functionality to your pages,
you've found that you're constantly following a pattern of selecting an element or
group of elements and operating upon those elements in some fashion. You
could be hiding or revealing the elements, adding a
CSS
class to them, animating
them, or modifying their attributes.
Using raw JavaScript can result in dozens of lines of code for each of these
tasks. The creators of jQuery specifically created the library to make common
tasks trivial. For example, designers will use JavaScript to "zebra-stripe" tables--
highlighting every other row in a table with a contrasting color--taking up to 10
lines of code or more. Here's how we accomplish it using jQuery:
$("table tr:nth-child(even)").addClass("striped");
Don't worry if that looks a bit cryptic to you right now. In short order, you'll under-
stand how it works, and you'll be whipping out your own terse--but powerful--


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

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