jQuery in Action 2nd Edition Bear Bibeault 2024 scribd download
jQuery in Action 2nd Edition Bear Bibeault 2024 scribd download
com
https://ebookname.com/product/jquery-in-action-2nd-edition-
bear-bibeault/
OR CLICK BUTTON
DOWNLOAD EBOOK
https://ebookname.com/product/jquery-in-action-1st-edition-bear-
bibeault/
ebookname.com
https://ebookname.com/product/jquery-ui-in-action-1st-edition-tj-
vantoll/
ebookname.com
https://ebookname.com/product/teddy-bear-teddy-bear-1st-edition-alice-
schertle/
ebookname.com
https://ebookname.com/product/boundary-elements-and-other-mesh-
reduction-methods-xxviii-v-28-c-a-brebbia/
ebookname.com
https://ebookname.com/product/american-railroad-labor-and-the-genesis-
of-the-new-deal-1919-1935-1st-edition-jon-r-huibregtse/
ebookname.com
https://ebookname.com/product/innate-and-adaptive-immunity-in-the-
tumor-microenvironment-eitan-yefenof/
ebookname.com
https://ebookname.com/product/seeing-things-whole-the-essential-john-
wesley-powell-first-edition-john-wesley-powell/
ebookname.com
https://ebookname.com/product/social-and-personal-identity-1st-
edition-derek-layder/
ebookname.com
The Bible in the Syriac Tradition Third Edition Sebastian
Brock
https://ebookname.com/product/the-bible-in-the-syriac-tradition-third-
edition-sebastian-brock/
ebookname.com
Bear Bibeault Covers jQuery 1.4 and jQuery UI 1.8
Yehuda Katz
IN ACTION
SECOND EDITION
MANNING
Praise for the First Edition
This is an excellent work, a worthy successor to others in Manning’s “In Action” series. It is
highly readable and chock-full of working code. The Lab pages are a marvelous way to explore
the library, which should become an important part of every web developer’s arsenal. Five stars
all ‘round!
—David Sills, JavaLobby, Dzone
I highly recommend the book for learning the fundamentals of jQuery and then serving as a good
reference book as you leverage the power of jQuery more and more in your daily development.
—David Hayden, MVP C#, Codebetter.com
For those new to jQuery, this book is a good primer that covers a range of common uses of the
framework.... The examples throughout the book are relevant, and make the point effectively.
The code snippets are easily distinguishable from the rest of the text, and the text is clear and
easy to follow.
—Grant Palin, Blogger
It works and makes for a very readable book that you can just breeze through very quickly and
pick up and retain a lot of information.
—Rich Strahl, Blogger
Thanks to the authors Bear Bibeault and Yehuda Katz and their exemplary style, this compre-
hensive book, or operating manual as it might be called, can be taken in a front-to-back approach
to learn from scratch, or as a reference to those already dabbling in jQuery and needing verifica-
tion of best practices.
—Matthew McCullough,
Denver Open Source Users Group
With its capable technical coverage, extensive use of sample code, and approachable style,
jQuery in Action is a valuable resource for any Web developer seeking to maximize the power
of JavaScript, and a must-have for anyone interested in learning jQuery.
—Michael J. Ross,
Web Developer, Slashdot Contributor
More Praise for the First Edition
An 8 out of 10—buy it! If you want to learn jQuery then this is an excellent book...
—John Whish, Founder,
Adobe ColdFusion User Group for Devon
I highly recommend this book to any novice or advanced JavaScript developers who finally want
to get serious about JavaScript and start writing optimized and elegant code without all the
hassle of traditional JavaScript code authoring.
—Val’s Blog
jQuery in Action offers a rich investigation of the up-and-coming jQuery library for client-side
JavaScript.
—www.DZone.com
I think that jQuery in Action is an excellent book that will help you learn and understand
jQuery. I certainly enjoyed reading the book.
—Gunnar Hillert,
Atlanta Java User Group
jQuery in Action
Second Edition
BEAR BIBEAULT
YEHUDA KATZ
MANNING
Greenwich
(74° w. long.)
For online information and ordering of this and other Manning books, please visit
www.manning.com. The publisher offers discounts on this book when ordered in quantity.
For more information, please contact
Special Sales Department
Manning Publications Co.
180 Broad St.
Suite 1323
Stamford, CT 06901
Email: orders@manning.com
Many of the designations used by manufacturers and sellers to distinguish their products are
claimed as trademarks. Where those designations appear in the book, and Manning
Publications was aware of a trademark claim, the designations have been printed in initial caps
or all caps.
Recognizing the importance of preserving what has been written, it is Manning’s policy to have
the books we publish printed on acid-free paper, and we exert our best efforts to that end.
Recognizing also our responsibility to conserve the resources of our planet, Manning books
are printed on paper that is at least 15 percent recycled and processed without the use of
elemental chlorine.
ISBN 978-1-935182-32-0
Printed in the United States of America
1 2 3 4 5 6 7 8 9 10 – MAL – 15 14 13 12 11 10
brief contents
PART 1 CORE JQUERY .............................................................. 1
1 ■ Introducing jQuery 3
2 ■ Selecting the elements upon which to act 18
3 ■ Bringing pages to life with jQuery 55
4 ■ Events are where it happens! 93
5 ■ Energizing pages with animations and effects 138
6 ■ Beyond the DOM with jQuery utility functions 169
7 ■ Expand your reach by extending jQuery 204
8 ■ Talk to the server with Ajax 235
v
contents
list of lab pages xiii
foreword to the first edition xv
preface to the second edition xvii
preface to the first edition xix
acknowledgments xxii
about this book xxv
about the authors xxx
about the cover illustration xxxii
1 Introducing jQuery
1.1
3
Power in the economy of code 4
1.2 Unobtrusive JavaScript 6
Separating behavior from structure 6 ■ Segregating the script 7
1.3 jQuery fundamentals 8
The jQuery wrapper 8 Utility functions 11 The document
■ ■
1.4 Summary 16
vii
viii CONTENTS
2.4 Summary 54
elements 64
3.2 Changing element styling 65
Adding and removing class names 66 ■ Getting and
setting styles 70
3.3 Setting element content 77
Replacing HTML or text content 77 Moving and copying
■
elements 88
3.4 Dealing with form element values 89
3.5 Summary 92
171
The browser detection flags 175
6.2 Using other libraries with jQuery 177
6.3 Manipulating JavaScript objects and collections 180
Trimming strings 180 Iterating through properties and
■
312
Controlling draggability 313
10.2 Dropping dragged things 314
Making elements droppable 315 ■ Droppability events 318
10.3 Sorting stuff 322
Making things sortable 323 Connecting sortables 327
■
Ajax 404
11.8 Dialog boxes 405
Creating dialog boxes 405 Dialog events 410
■ ■ Dialog box class
names 411 Some dialog box tricks 412
■
xiii
foreword to the first edition
It’s all about simplicity. Why should web developers be forced to write long, complex,
book-length pieces of code when they want to create simple pieces of interaction?
There’s nothing that says that complexity has to be a requirement for developing web
applications.
When I first set out to create jQuery I decided that I wanted an emphasis on small,
simple code that served all the practical applications that web developers deal with
day to day. I was greatly pleased as I read through jQuery in Action to see in it an excel-
lent manifestation of the principles of the jQuery library.
With an overwhelming emphasis on practical, real-world code presented in a terse,
to-the-point format, jQuery in Action will serve as an ideal resource for those looking
to familiarize themselves with the library.
What’s pleased me the most about this book is the significant attention to detail
that Bear and Yehuda have paid to the inner workings of the library. They were thor-
ough in their investigation and dissemination of the jQuery API. It felt like nary a day
went by in which I wasn’t graced with an email or instant message from them asking
for clarification, reporting newly discovered bugs, or recommending improvements to
the library. You can be safe knowing that the resource that you have before you is one
of the best thought-out and researched pieces of literature on the jQuery library.
One thing that surprised me about the contents of this book is the explicit inclu-
sion of jQuery plugins and the tactics and theory behind jQuery plugin development.
The reason why jQuery is able to stay so simple is through the use of its plugin
xv
xvi FOREWORD TO THE FIRST EDITION
JOHN RESIG
CREATOR OF jQUERY
preface to the second edition
It’s been two years since the first edition of jQuery in Action was published. Was it really
necessary to update the book so soon?
Absolutely!
Compared to the steady world of server-side languages such as Java, the client-side
technologies of the web move at a mighty fast clip. And jQuery isn’t eating anyone’s
dust; rather, it’s at the forefront of the rush!
The jQuery team releases a major new version of the library just about every year
(lately, striving for every January), in addition to the minor updates that are made
throughout the calendar year. That means that there have been numerous minor
releases, and two major versions since the publication of the first edition, which was
written against jQuery 1.2. And what updates jQuery 1.3 and jQuery 1.4 have been!
With each major release, the capabilities of jQuery have been extended and
enhanced in significant ways. Whether it be the addition of custom events, event
namespaces, function and effect queuing, or simply the large handful of really useful
methods and functions that have been added, the range of capabilities that jQuery
spans has increased significantly since the first edition hit the stands.
And that doesn’t even consider jQuery UI! In its nascent stages two years ago,
jQuery UI merited a few sections in one chapter of the first edition. Since then, jQuery
UI has grown in scope and maturity and warrants a complete book part in this edition,
consisting of three full chapters.
So it should come as no surprise that this second edition has made its way onto
the shelves covering the advances that jQuery and jQuery UI have made over the past
two years.
xvii
xviii PREFACE TO THE SECOND EDITION
xix
xx PREFACE TO THE FIRST EDITION
“J who?” I asked.
I was promptly treated to a detailed dissertation on how wonderful this fairly new
library was and how it really should be part of any modern examination of Ajax-
enabling client-side libraries. I asked around a bit. “Have any of you ever heard of this
jQwerty library?”
I received a large number of positive responses, all enthusiastic and all agreeing
that jQuery really was the cat’s pajamas. On a rainy Sunday afternoon, I spent about
four hours at the jQuery site reading documentation and writing little test programs to
get a feel for the jQuery way of doing things. Then I banged out the new section and
sent it to the technical editor to see if I had really gotten it.
The section was given an enthusiastic thumb’s up, and we went on to finally com-
plete the Ajax in Practice book. (That section on jQuery eventually went on to be pub-
lished in the online version of Dr. Dobb’s Journal.)
When the dust had settled, my frenzied exposure to jQuery had planted relentless
little seeds in the back of my mind. I’d liked what I’d seen during my headlong
research into jQuery, and I set out to learn more. I started using jQuery in web proj-
ects. I still liked what I saw. I started replacing older code in previous projects to see
how jQuery would simplify the pages. And I really liked what I saw.
Enthusiastic about this new discovery and wanting to share it with others, I took
complete leave of my senses and submitted a proposal for jQuery in Action to Manning.
Obviously, I must’ve been convincing. (As penance for causing such mayhem, I asked
the technical editor who started all the trouble to also be the technical editor for this
book. I’ll bet that taught him!)
It’s at that point that the editor, Mike Stephens, asked, “How would you like to
work with Yehuda Katz on this project?”
“Yehenta who?” I asked…
Yehuda came to this project by a different route; his involvement with jQuery predates
the days when it even had version numbers. After he stumbled on the Selectables
Plugin, his interest in the jQuery core library was piqued. Somewhat disappointed by
the (then) lack of online documentation, he scoured the wikis and established the
Visual jQuery site (visualjquery.com).
Before too long, he was spearheading the push for better online documents, con-
tributing to jQuery, and overseeing the plugin architecture and ecosystem, all while
evangelizing jQuery to the Ruby community.
Then came the day when he received a call from Manning (his name having been
dropped to the publisher by a friend), asking if he’d be interested in working with this
Bear guy on a jQuery book…
Despite the differences in our backgrounds, experiences, and strengths, and the man-
ner in which we came together on this project, we’ve formed a great team and have
PREFACE TO THE FIRST EDITION xxi
had a lot of fun working together. Even geographic distance (I’m in the heart of
Texas, and Yehuda is on the California coast) proved no barrier. Thank goodness for
email and instant messaging!
We think that the combination of our knowledge and talents brings you a strong
and informative book. We hope you have as much fun reading this book as we had
working on it.
We just advise you to keep saner hours.
acknowledgments
Have you ever been surprised, or even bewildered, by the seemingly endless list of
names that scrolls up the screen during the ending credits of a motion picture? Do
you ever wonder if it really takes that many people to make a movie?
Similarly, the number of people involved in the writing of a book would probably
be a big surprise to most people. It takes a large collaborative effort on the part of
many contributors with a variety of talents to bring the volume you are holding (or
ebook that you are reading onscreen) to fruition.
The staff at Manning worked tirelessly with us to make sure that this book
attained the level of quality that we hoped for, and we thank them for their efforts.
Without them, this book would not have been possible. The “end credits” for this
book include not only our publisher, Marjan Bace, and editor Mike Stephens, but
also the following contributors: Lianna Wlasiuk, Karen Tegtmayer, Andy Carroll,
Deepak Vohra, Barbara Mirecki, Megan Yockey, Dottie Marsico, Mary Piergies,
Gabriel Dobrescu, and Steven Hong.
Enough cannot be said to thank our peer reviewers who helped mold the final
form of the book, from catching simple typos to correcting errors in terminology and
code and even helping to organize the chapters within the book. Each pass through a
review cycle ended up vastly improving the final product. For taking the time to help
review the book, we’d like to thank Tony Niemann, Scott Sauyet, Rich Freedman,
Philip Hallstrom, Michael Smolyak, Marion Sturtevant, Jonas Bandi, Jay Blanchard,
Nikander Bruggeman, Margriet Bruggeman, Greg Donald, Frank Wang, Curtis Miller,
Christopher Haupt, Cheryl Jerozal, Charles E. Logston, Andrew Siemer, Eric
xxii
ACKNOWLEDGMENTS xxiii
Raymond, Christian Marquardt, Robby O’Connor, Marc Gravell, Andrew Grothe, Anil
Radhakrishna, Daniel Bretoi, and Massimo Perga.
Very special thanks go to Valentin Crettaz, who served as the book’s technical edi-
tor. In addition to checking each and every sample of example code in multiple envi-
ronments, he also offered invaluable contributions to the technical accuracy of the
text, located information that was originally missing, kept abreast of rapid changes to
the libraries while we were writing to make sure that the book represented an up-to-
date and accurate view of jQuery and jQuery UI, and even provided the PHP versions
of the examples requiring server-side code.
Bear Bibeault
For this, my fourth published tome, the cast of characters I’d like to thank has a long
list of “usual suspects,” including, once again, the membership and staff at
javaranch.com. Without my involvement in JavaRanch, I’d never have gotten the
opportunity to start writing in the first place, and so I sincerely thank Paul Wheaton
and Kathy Sierra for starting the whole thing, as well as fellow staffers who gave me
encouragement and support, including (but probably not limited to) Eric Pascarello,
Ben Souther, Ernest Friedman Hill, Mark Herschberg, Andrew Munkhouse, Jeanne
Boyarski, Bert Bates, and Max Habbibi.
Thanks go out to Valentin Crettaz, not only for serving as a superb technical editor
and code contributor (as noted above), but also for introducing me to jQuery in the
first place.
My partner Jay, and my dogs, Little Bear and Cozmo (whose visages grace the
pages of this book), get the usual warm thanks for putting up with the shadowy pres-
ence who shared their home but who rarely looked up from his MacBook Pro key-
board for all the months it took to write this book.
And finally, I’d like to thank my coauthor, Yehuda Katz, without whom this project
would not have been possible, as well as John Resig and the rest of the jQuery and
jQuery UI contributors.
Yehuda Katz
To start, I’d like to thank Bear Bibeault, my coauthor, for the benefit of his exten-
sive writing experience. His talented writing and impressive abilities to navigate the
hurdles of professional publishing were a tremendous part of what made this book
possible.
While speaking of making things possible, it’s necessary that I thank my lovely wife
Leah, who put up with the long nights and working weekends for far longer than I
would have felt comfortable asking. Her dedication to completing this book rivaled
even my own; and, as in all things, she made the most difficult part of this project
bearable. I love you, Leah.
Obviously, there would be no jQuery in Action without the jQuery library itself. I’d
like to thank John Resig, the creator of jQuery, for changing the face of client-side
xxiv ACKNOWLEDGMENTS
development and easing the burden of web developers across the globe (believe it or
not, we have sizable user groups in China, Japan, France, and many other countries). I
also count him as a friend who, as a talented author himself, helped me to prepare for
this tremendous undertaking.
There would be no jQuery without the incredible community of users and core
team members, including Brandon Aaron and Jörn Zaefferer on the development
team; Rey Bango and Karl Swedberg on the evangelism team; Paul Bakaus, who heads
up jQuery UI; and Klaus Hartl and Mike Alsup, who work on the plugins team with
me. This great group of programmers helped propel the jQuery framework from a
tight, simple base of core operations to a world-class JavaScript library, complete with
user-contributed (and modular) support for virtually any need you could have. I’m
probably missing a great number of jQuery contributors; there are a lot of you guys.
Suffice it to say that I would not be here without the unique community that has come
up around this library, and I can’t thank you enough.
Lastly, I want to thank my family, whom I don’t see nearly enough since my recent
move across the country. Growing up, my siblings and I shared a tight sense of camara-
derie, and the faith my family members have in me has always made me imagine I can
do just about anything. Mommy, Nikki, Abie, and Yaakov: thank you, and I love you.
Another Random Scribd Document
with Unrelated Content
APPENDIX XIV
chronological sketch of afghan history
MAP OF
AFGHANISTAN
BY
Angus Hamilton
Fellow of the Royal Geographical Society
London: H. Heinemann. Stanford’s Geogˡ Estabᵗ London
INDEX
Abdur Rahman, 91, 152, 247, 253, 258, 355-356, 433
Accession of Habib Ullah and, 432
Administrative system of, 269, 272
Afridi Elders and, 421-422, 424
Army under, 318-321, 325
Chitral crisis and, 415
Decline and death of, 432-434, 439
Lord Dufferin and, 401
Sir M. Durand and, 406
Lord Elgin and, 416, 418, 420
Europeans employed by, 394
Fiscal policy of, 231, 290-291
Foreign relations, 356-357, 403, 446
Frontier disturbances, 419, 422, 424
Gifts to, 402
Gun-running, 397
Sir Lepel Griffin and, 400
Imports of munitions, 407
Indian Government and, 419-425
Invited to England, 409
Mobilisation scheme, 432
Mullahs and, 415-416, 442
Queen Victoria, 433
Reception of Turkish visitor by, 416
Recognition of, as Amir, 400
Refusal to visit India, 403
Refusal to receive Roberts Mission, 405
Lord Ripon and, 400
Shir Afzal, 413, 414
and South African War, 432
Subsidy, 407
Swat-Tochi rising, 417
Theological studies of, 415
Treaties, 406, 412, 455
Tribal affairs, 270-271, 443, 447
Visits Afghan-Turkestan, 402
Warns Viceroy, 409
Western therapeutics and, 389
Abramoff, General, 40
Adiz Abad, 69
Afghan Turkestan, 94, 242, 262
Area of, 247
Coal deposits in, 396
Subjugation of, 250
Visited by Abdur Rahman, 402
Afghan War, First, 148
Second, 151, 152, 448
Afghanistan, administrative system of, 269-287
British relations with, 147-149, 155-156, 187-189, 220, 250, 356,
373, 375, 446, 455, 457, 458
Climate of, 261, 262
Currency of, 283
Ethnographic distribution, 262-263, 267-268
Khanates of, 250-253
Laws of, 275-280
Minerals of, 304
Orology of, 259, 260
Products and manufactures, 298-307
Provinces of, 242-247
Revenue of, 282-287
Rivers in, 260-276 (See Rivers)
Russian relations with, 121-122, 356, 440, 443, 447, 457-458
Trade of, 236, 288-298, 306
Afridis, 264, 408, 417, 418, 419, 423, 446
Agerskski valley, 14
Agreements (See Treaties)
Ahmed Khan, Sirdar, 189
Ahmed, Shah, tomb of, 190, 193
Akcha, 247, 258
Akrobat, 401
Aktash, 174
Ak-Tepe, 117
Aktinbinsk, 6, 7, 9, 13, 14
Alai mountains, 25, 26, 30
Alayar Khan, 62
Alcock, Surgeon-Captain A. W., 156
Alexander II., 60
Alexander of Macedon, 58, 62, 109
Alexandrovski, 18
Alexeieffski, 120, 124
Alichm Pamir, 174
Ali Mardan Khan, 377
Ali Masjid, 419 (See also Khyber)
Ali Yai Khan, remarks of, 445
Alvar, 259
Amir Ullah Khan, 362, 436
Ampthill, Lord, 452
Amritsar, 202
Amu Daria (See Oxus)
Amu Daria flotilla, 74, 75, 96, 97, 98, 102-104
Anardara, 204
Anderab, 244, 253
Anderson, Mr., 409
Andijan, 6, 11, 43, 49, 59, 110
Andkhui, 173, 242, 247, 258-259
Anglo-Afghan Boundary Mission, 155
Anglo-Russian Boundary Mission, 138, 141
Annenkoff, General, 7, 76
Annenkovo, 76, 77
Aral sea, 10, 16, 95, 96
Ardewan pass, 126, 157
Aris, 11
Army, 308-326
Under Abdur Rahman, 318-321, 325
Under Dost Mahommed, 308-311
Under Habib Ullah, 321-324
Under Shir Ali, 311-318
Askhabad, 3, 4, 5, 11, 70, 103, 173
Aslam Khan, Colonel, 419
Asmar valley, 403, 408, 425
Auckland, Lord, 1, 148
Aulie-ata, 8
Ayub Khan, 152, 187
Baber, 346
Badakshan, 242, 243, 244, 250-253, 405
Badghis, 156
Bad-i-sad-o-bist roz, 223
Badjira, 129
Baghdad, 237, 238
Baglan, 253
Bairam Ali, 77, 78, 79
Bajaur-Mohmands, 408, 412, 413, 414, 417
Bakhtiaris, 204
Bakwa plain, 181
Bala Murghab, 119, 135, 142
Balfour, Mr. A. J., speeches of, 457
Balkan hills, 96
Balkash, 8
Balkh, 173, 177, 242, 247, 250, 256-257, 260, 310-311
Balkh-Herat route, list of marches, 329-330
Baluchis, 204, 226, 227, 228, 241
Baluchistan, 189
Bam, 237
Bamian, 182, 243, 247
Band-i-Turkestan, 258
Bangash, Upper, 243
Bannu, 429
Barak pass, 228
Barakail, 250
Barkhani, 76
Barnaul, 8
Baroghil pass, 244
Barton, Captain, 419
Basawul, 359
Basra, 238
Basra-Baghdad-Kermanshah-Teheran route, comparison of, with
Nushki-Seistan route, 237, 238
Belgian customs in Seistan, 235
Beetroot in Chimkent district, 19
Bell, Captain R. C., 241
Bellew, cited, 197
Benadar Kalan, 185
Benn, Major, 232
Ber Kazan, 10
Bibi Halima, 360, 361, 366, 369
Biggs, General Yeatman, 419
Binket (See Tashkent)
Bird, Major, 357, 358, 394, 395
Bird, General Corrie, 416
Bish Agatchski, 49
Black Sands of Bokhara (See Kara Kum)
Blood, General Sir Bindon, 417, 425
Bodorodski, 59
Bokhara, Khanate of, 25-39
City, 2, 6, 30, 36-39, 49, 52, 70-71, 104
Bazaars, 34, 44
Commercial relations, 70, 71
Imports from Kandahar, 203
Irrigation, 94
Masjid-i-Jama, 36
Medjidi Kalyan, 35
Medresse Mir-i-Arab, 36
Minai Kalan, 36
Population, 26, 29, 30, 33
Products, 29-30
Registan, 34
Soil, 29-30
Submission to Russia, 150
Walls of, 30
Water difficulty, 25, 26, 33, 72
Women in, 33, 34
Bolan pass, 230
Bombay, imports from, into Kandahar, 201-202
Bori valley, 260
Bozai Gumbaz, 85
British agent in Kabul, 374
Agent at Koh-i-Malik-Siah, 234
Interests in Persia, 220 in Seistan, 241
Merchants at Bunder Abbas, 237
Relations with Afghanistan, 147, 148, 149, 155, 156, 220, 250,
373-375, 446, 454, 457, 458
Relations with Russia, 1-3, 187, 188, 189, 448
Support of Abdur Rahman as Amir, 356
Brett, Lieutenant, 241
Brodrick, Mr. St. John, 452
Brooke, Captain Victor, 453
Brown, The Misses, 354, 395, 399
Bruce, Mr., 409
Buluna Khel, 408
Bunder Abbas, 234, 237
British merchants at, 237
Rate of camel-hire, 234
Buner, 408
Burnes, Alexander, 147-148
Burrows, General, 152, 187
Bushire, 237
Bustan, 69
Butkhak, 243