spine=1.0646" Wrox Programmer to ProgrammerTM Wrox Programmer to ProgrammerTM Beginning r o York l o JavaScript and CSS Development with C ® l l u jQuery F jQuery allows you to do more in the world of dynamic web applications, with less code Beginning and fewer errors. It reduces the amount of JavaScript programming to only a few lines of code while making your JavaScript more intuitive and attractive to work with. At the jJ same time, jQuery makes it easier to manipulate CSS from JavaScript by allowing you Qa to set style for one or many elements at once. v With this unique, project-oriented book, author Richard York teaches even the most a novice of JavaScript users how to quickly get started utilizing the JavaScript jQuery uS Library to decrease the amount of code that needs to be written and tested. A four- c color code syntax highlighting system provides a visual reinforcement and allows you e r to see the nuts and bolts that comprise each line and section of code. With this helpful i guide and hands-on exercises, you’ll be able to put jQuery to work for you and avoid rp having to write code from scratch. t y ® What you will learn from this book a ● How to install and test jQuery n ● Techniques to manipulate content and attributes d ● Ways to filter and map a selection or an array ● The difference between GET and POST C Beginning ● How to easily show, hide, slide, and fade elements with smooth animations and S transitions S ● Good practice for jQuery plugin development ● Methods for making elements draggable D JavaScript and CSS ● Ways to customize sortable lists e ® ● How to implement and localize a datepicker Enhance Your Knowledge v Advance Your Career e Who this book is for l This book is for web designers eager to do more with their web-based applications, o Development with but who do not necessarily have much JavaScript experience. Some basic knowledge p of XHTML and CSS is necessary. m e jQuery Wrox Beginning guides are crafted to make learning programming languages and technologies easier than you think, providing n a structured, tutorial format that will guide you through all the techniques involved. t w i www.wrox.com t h With full-color code and illustrations ISBN: 978-0-470-22779-4 Recommended Programming Languages Computer Book Richard York Categories JavaScript and VBScript $44.99 USA Updates, source code, and Wrox technical support at www.wrox.com $53.99 CAN 23642ffirs.indd 4 5/4/09 12:57:35 PM Beginning JavaScript® and CSS Development with jQuery Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix Part I: jQuery API 1 Chapter 1: Introduction to jQuery . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3 Chapter 2: Selecting and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 Chapter 3: Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69 Chapter 4: Manipulating Content and Attributes . . . . . . . . . . . . . . . . . . . . . . 95 Chapter 5: Arrays and Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165 Chapter 6: CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207 Chapter 7: AJAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219 Chapter 8: Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277 Chapter 9: Plugins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285 Part II: jQuery UI 297 Chapter 10: Implementing Drag-and-Drop . . . . . . . . . . . . . . . . . . . . . . . . . . 299 Chapter 11: Drag-and-Drop Sorting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327 Chapter 12: Selection by Drawing a Box . . . . . . . . . . . . . . . . . . . . . . . . . . . 355 Chapter 13: Accordion UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 373 Chapter 14: Datepicker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 393 Chapter 15: Dialogs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 409 Chapter 16: Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425 Appendix A: Answers to Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 439 Appendix B: Selectors Supported by jQuery . . . . . . . . . . . . . . . . . . . . . . . . 447 Appendix C: Selecting and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451 Appendix D: Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 453 Appendix E: Manipulating Attributes and Data Caching . . . . . . . . . . . . . . . . 457 Appendix F: Manipulating Content . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 459 Appendix G: AJAX Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46 1 Appendix H: CSS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465 Appendix I: Utilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 467 Appendix J: Draggables and Droppables . . . . . . . . . . . . . . . . . . . . . . . . . . . 469 Appendix K: Sortables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475 27794ffirs.indd 1 3/16/09 3:14:20 PM Appendix L: Selectables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 479 Appendix M: Effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 481 Appendix N: Accordion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485 Appendix O: Datepicker . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 487 Appendix P: Dialog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 497 Appendix Q: Tabs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 501 Appendix R: Re-Sizables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505 Appendix S: Sliders . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 509 Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 511 27794ffirs.indd 2 3/16/09 3:14:20 PM Beginning JavaScript®and CSS Development with jQuery 27794ffirs.indd 3 3/16/09 3:14:20 PM 27794ffirs.indd 4 3/16/09 3:14:20 PM Beginning JavaScript®and CSS Development with jQuery Richard York 27794ffirs.indd 5 3/16/09 3:14:20 PM 23642ffirs.indd 4 5/4/09 12:57:35 PM Beginning JavaScript® and CSS Development with jQuery Published by Wiley Publishing, Inc. 10475 Crosspoint Boulevard Indianapolis, IN 46256 www.wiley.com Copyright © 2009 by Wiley Publishing, Inc., Indianapolis, Indiana Published simultaneously in Canada ISBN: 978-0-470-22779-4 Manufactured in the United States of America 10 9 8 7 6 5 4 3 2 1 Library of Congress Cataloging-in-Publication Data York, Richard. Beginning JavaScript and CSS development with jQuery / Richard York. p. cm. Includes index. ISBN 978-0-470-22779-4 (paper/website) 1. JavaScript (Computer program language) 2. Web sites--Design. 3. Cascading style sheets. I. Title. QA76.73.J38Y67 2009 006.7’6--dc22 2009005636 No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions. Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or pro- motional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read. For general information on our other products and services please contact our Customer Care Department within the United States at (877) 762-2974, outside the United States at (317) 572-3993 or fax (317) 572-4002. Trademarks: Wiley, the Wiley logo, Wrox, the Wrox logo, Programmer to Programmer, and related trade dress are trade- marks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. JavaScript is a registered trademark of Sun Microsystems, Inc. All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated with any product or vendor mentioned in this book. Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may not be available in electronic books. 27794ffirs.indd 6 3/16/09 3:14:20 PM About the Author Richard York is a web developer and author of three Wrox books in addition to this: Beginning CSS: Cascading Style Sheets for Web Design (Wiley, 2007), CSS Instant Results (Wiley, 2006), and Beginning CSS: Cascading Style Sheets for Web Design, 2nd ed (Wiley, 2007). Website: www.deadmarshes.com 27794ffirs.indd 7 3/16/09 3:14:20 PM