CYAN YELLOW MAGENTA BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN WEB DEVELOPMENT More Free Ebook: www.latestebook.com Companion jQuery Recipes: eBook Available A Problem-Solution Approach j Q Dear Reader, The jQuery framework is fantastically powerful and elegant, but it still has enough thorny edges to snag unwary users. jQuery Recipes is chock full of solu- u tions to those thorny problems, over a hundred of them, ranging from the com- jQuery mon to the more obscure. We cover areas such as: B.M. Harwani e Author of • Handling keyboard and mouse events • Form validation techniques Foundation Joomla • Applying animation effects r • Manipulating the DOM • Advanced table handling y • Working with JSON and XML data For each problem, we carefully define what the issue is first, and then pro- vide the code solution along with any required HTML and CSS to get the exam- R Recipes ple working. Where there are numerous permutations to the problem, we’ll run through a set of solutions to keep you fully armed for all eventualities. The code is then carefully explained so that you understand the core details of the solution e and can apply them to your own code any time you come across a similar issue. Along with using the book as a reference to dip into for answers, you can also use it for increasing your knowledge of jQuery. By reading through the solutions c and trying out the fully illustrated and explained sample code, you will gain a bet- ter understanding of the inner workings of the jQuery framework and how it can i be used to make your websites more dynamic and sticky. A Problem-Solution Approach p B.M. Harwani e THE APRESS ROADMAP s Companion eBook jQuery Recipes Pro JavaScript Techniques An expert compilation of solutions Beginning JavaScript to real-world jQuery problems Practical JavaScript Projects Pro JavaScript RIA Techniques See last page for details on $10 eBook version B.M. Harwani SOURCE CODE ONLINE www.apress.com ISBN 978-1-4302-2709-0 54499 Harwani US $44.99 Shelve in: Web Development User level: Intermediate 9 781430 227090 More Free Ebook: www.latestebook.com www.it-ebooks.info this print for content only—size & color not accurate trim = 7.5" x 9.25" spine = 0.000" 000 page count CYAN YELLOW MAGENTA BLACK PANTONE 123 C BOOKS FOR PROFESSIONALS BY PROFESSIONALS® THE EXPERT’S VOICE® IN WEB DEVELOPMENT More Free Ebook: www.latestebook.com Companion jQuery Recipes: eBook Available A Problem-Solution Approach j Q Dear Reader, The jQuery framework is fantastically powerful and elegant, but it still has enough thorny edges to snag unwary users. jQuery Recipes is chock full of solu- u tions to those thorny problems, over a hundred of them, ranging from the com- jQuery mon to the more obscure. We cover areas such as: B.M. Harwani e Author of • Handling keyboard and mouse events • Form validation techniques Foundation Joomla • Applying animation effects r • Manipulating the DOM • Advanced table handling y • Working with JSON and XML data For each problem, we carefully define what the issue is first, and then pro- vide the code solution along with any required HTML and CSS to get the exam- R Recipes ple working. Where there are numerous permutations to the problem, we’ll run through a set of solutions to keep you fully armed for all eventualities. The code is then carefully explained so that you understand the core details of the solution e and can apply them to your own code any time you come across a similar issue. Along with using the book as a reference to dip into for answers, you can also use it for increasing your knowledge of jQuery. By reading through the solutions c and trying out the fully illustrated and explained sample code, you will gain a bet- ter understanding of the inner workings of the jQuery framework and how it can i be used to make your websites more dynamic and sticky. A Problem-Solution Approach p B.M. Harwani e THE APRESS ROADMAP s Companion eBook jQuery Recipes Pro JavaScript Techniques An expert compilation of solutions Beginning JavaScript to real-world jQuery problems Practical JavaScript Projects Pro JavaScript RIA Techniques See last page for details on $10 eBook version B.M. Harwani SOURCE CODE ONLINE www.apress.com ISBN 978-1-4302-2709-0 54499 Harwani US $44.99 Shelve in: Web Development User level: Intermediate 9 781430 227090 More Free Ebook: www.latestebook.com www.it-ebooks.info this print for content only—size & color not accurate trim = 7.5" x 9.25" spine = 0.000" 000 page count More Free Ebook: www.latestebook.com jQuery Recipes ■ ■ ■ B.M. Harwani More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com jQuery Recipes Copyright © 2010 by B.M. Harwani All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher. ISBN-13 (pbk): 978-1-4302-2709-0 ISBN-13 (electronic): 978-1-4302-2710-6 Printed and bound in the United States of America 9 8 7 6 5 4 3 2 1 Trademarked names may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, we use the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. President and Publisher: Paul Manning Lead Editor: Steve Anglin Developmental Editor: Matthew Moodie Technical Reviewer: Massimo Nardone Editorial Board: Clay Andres, Steve Anglin, Mark Beckner, Ewan Buckingham, Gary Cornell, Jonathan Gennick, Jonathan Hassell, Michelle Lowman, Matthew Moodie, Duncan Parkes, Jeffrey Pepper, Frank Pohlmann, Douglas Pundick, Ben Renow-Clarke, Dominic Shakeshaft, Matt Wade, Tom Welsh Coordinating Editor: Kelly Moritz Copy Editor: Candace English Production Support: Patrick Cunningham Indexer: Artist: April Milne Cover Designer: Anna Ishchenko Distributed to the book trade worldwide by Springer-Verlag New York, Inc., 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax 201-348-4505, e-mail orders- [email protected], or visit http://www.springeronline.com. For information on translations, please e-mail [email protected], or visit http://www.apress.com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Special Bulk Sales–eBook Licensing web page at http://www.apress.com/info/bulksales. The information in this book is distributed on an “as is” basis, without warranty. Although every precaution has been taken in the preparation of this work, neither the author(s) nor Apress shall have any liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by the information contained in this work. More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com To my mother Mrs. Nita Harwani. My mother is next to God for me. Whatever I am today is just because of the Moral values taught by her To Dennis Ritchie and Ken Thompson - the creators of UNIX. I appreciate Ken Thompson’s work with B programming language and have been fond of programming in Ritchie’s invention: ‘C’ programming language since I was doing Engineering. I am a great admirer of the security features of Unix and used to love making shell scripts on UNIX operating sytem during my study days. Their achievments are the inspiration for the millions of programmers around the world. More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com Contents at a Glance About the Author................................................................................................ xxviii About the Technical Reviewer ............................................................................. xxix Acknowledgments ................................................................................................ xxx Introduction ......................................................................................................... xxxi ■ Chapter 1: jQuery Basics .......................................................................................1 ■ Chapter 2: Arrays and Strings .............................................................................17 ■ Chapter 3: Event Handling ...................................................................................45 ■ Chapter 4: Form Validation ................................................................................107 ■ Chapter 5: Page Navigation ...............................................................................167 ■ Chapter 6: Visual Effects ...................................................................................199 ■ Chapter 7: Dealing with Tables ..........................................................................253 ■ Chapter 8: Ajax ..................................................................................................291 ■ Chapter 9: Using Plugins ...................................................................................327 ■ Chapter 10: Using CSS .......................................................................................357 Index .....................................................................................................................409 iv More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com Contents About the Author................................................................................................ xxviii About the Technical Reviewer ............................................................................. xxix Acknowledgments ................................................................................................ xxx Introduction ......................................................................................................... xxxi ■ Chapter 1: jQuery Basics .......................................................................................1 1-1. Installing jQuery....................................................................................................... 1 Problem ................................................................................................................................................. 1 Solution ................................................................................................................................................. 2 How It Works ......................................................................................................................................... 2 1-2. Selecting Nodes in the DOM .................................................................................... 2 Problem ................................................................................................................................................. 2 Solution ................................................................................................................................................. 2 How It Works ......................................................................................................................................... 3 1-3. Delaying the Execution of JavaScript ...................................................................... 3 Problem ................................................................................................................................................. 3 Solution ................................................................................................................................................. 3 How It Works ......................................................................................................................................... 3 1-4. Applying CSS to Elements ....................................................................................... 4 Problem ................................................................................................................................................. 4 Solution ................................................................................................................................................. 4 How It Works ......................................................................................................................................... 4 v More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com ■ CONTENTS 1-5. Selecting a Non-Standard Series of HTML Elements .............................................. 4 Problem ................................................................................................................................................. 4 Solution ................................................................................................................................................. 4 How It Works ......................................................................................................................................... 5 1-6. Counting the Number of Nodes in the DOM and Displaying Their Text ................... 5 Problem ................................................................................................................................................. 5 Solution ................................................................................................................................................. 5 How It Works ......................................................................................................................................... 6 1-7. Obtaining the HTML of an Element .......................................................................... 8 Problem ................................................................................................................................................. 8 Solution ................................................................................................................................................. 8 How It Works ......................................................................................................................................... 8 1-8. Changing the Content of a DOM Node ..................................................................... 9 Problem ................................................................................................................................................. 9 Solution ................................................................................................................................................. 9 How It Works ....................................................................................................................................... 10 1-9. Creating a DOM Node on the Fly ........................................................................... 11 Problem ............................................................................................................................................... 11 Solution ............................................................................................................................................... 12 How It Works ....................................................................................................................................... 13 1-10. Assigning the Same Class Name to Different HTML Elements and Applying Styles to Them ........................................................................ 14 Problem ............................................................................................................................................... 14 Solution ............................................................................................................................................... 15 How It Works ....................................................................................................................................... 16 Summary ...................................................................................................................... 16 vi More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com ■ CONTENTS ■ Chapter 2: Arrays and Strings .............................................................................17 2-1. Displaying Names in a List Using Arrays ............................................................... 17 Problem ............................................................................................................................................... 17 Solution ............................................................................................................................................... 18 How It Works ....................................................................................................................................... 19 2-2. Manipulating Array Elements ................................................................................ 21 Problem ............................................................................................................................................... 21 Solution ............................................................................................................................................... 21 How It Works ....................................................................................................................................... 23 2-3. Filtering Arrays to Show Desired Data Only .......................................................... 24 Problem ............................................................................................................................................... 24 Solution ............................................................................................................................................... 24 How It Works ....................................................................................................................................... 25 2-4. Sorting String and Numerical Arrays ..................................................................... 30 Problem ............................................................................................................................................... 30 Solution ............................................................................................................................................... 30 How It Works ....................................................................................................................................... 31 2-5. Splitting an Array ................................................................................................... 33 Problem ............................................................................................................................................... 33 Solution ............................................................................................................................................... 33 How It Works ....................................................................................................................................... 34 2-6. Combining Two Arrays .......................................................................................... 35 Problem ............................................................................................................................................... 35 Solution ............................................................................................................................................... 35 How It Works ....................................................................................................................................... 36 vii More Free Ebook: www.latestebook.com www.it-ebooks.info More Free Ebook: www.latestebook.com ■ CONTENTS 2-7. Converting a Numerical Array into a String and Finding Its Substring .................. 37 Problem ............................................................................................................................................... 37 Solution ............................................................................................................................................... 37 How It Works ....................................................................................................................................... 37 2-8. Creating an Array of Objects ................................................................................. 38 Problem ............................................................................................................................................... 38 Solution ............................................................................................................................................... 38 How It Works ....................................................................................................................................... 39 2-9. Sorting an Array of Objects ................................................................................... 40 Problem ............................................................................................................................................... 40 Solution ............................................................................................................................................... 41 How It Works ....................................................................................................................................... 42 Summary ...................................................................................................................... 43 ■ Chapter 3: Event Handling ...................................................................................45 3-1. Finding Out Which Button Is Clicked ..................................................................... 46 Problem ............................................................................................................................................... 46 Solution ............................................................................................................................................... 46 How It Works ....................................................................................................................................... 48 3-2. Triggering Events Automatically ........................................................................... 50 Problem ............................................................................................................................................... 50 Solution ............................................................................................................................................... 51 How It Works ....................................................................................................................................... 51 trigger() ................................................................................................................................................ 52 3-3. Disabling a Button After It Is Clicked Once ............................................................ 52 Problem ............................................................................................................................................... 52 Solution ............................................................................................................................................... 53 How It Works ....................................................................................................................................... 53 viii More Free Ebook: www.latestebook.com www.it-ebooks.info
Description: