this print for content only—size & color not accurate trim = 7.5" x 9.25" spine = 0.000" 000 page count BOOKS FOR PROFESSIONALS BY PROFESSIONALS ® Harwani jQuery Recipes Companion eBook Available US $44.99 Shelve in: Web Development User level: Intermediate www.apress.com SOURCE CODE ONLINE Companion eBook See last page for details on $10 eBook version ISBN 978-1-4302-2709-0 9 781430 227090 5 44 9 9 jQuery Recipes: A Problem-Solution Approach 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- tions to those thorny problems, over a hundred of them, ranging from the com- mon to the more obscure. We cover areas such as: • Handling keyboard and mouse events • Form validation techniques • Applying animation effects • Manipulating the DOM • Advanced table handling • 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- 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 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 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 be used to make your websites more dynamic and sticky. B.M. Harwani THE EXPERT’S VOICE ® IN WEB DEVELOPMENT jQuery Recipes A Problem-Solution Approach B.M. Harwani An expert compilation of solutions to real-world jQuery problems THE APRESS ROADMAP jQuery Recipes Practical JavaScript Projects Beginning JavaScript Pro JavaScript Techniques Pro JavaScript RIA Techniques CYAN MAGENTA YELLOW BLACK PANTONE 123 C B.M. Harwani Author of Foundation Joomla More free ebooks : http://fast-file.blogspot.com jQuery Recipes ■ ■ ■ B.M. Harwani More free ebooks : http://fast-file.blogspot.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- ny@springer-sbm.com, or visit http://www.springeronline.com. For information on translations, please e-mail info@apress.com, 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 ebooks : http://fast-file.blogspot.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 ebooks : http://fast-file.blogspot.com iv 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 More free ebooks : http://fast-file.blogspot.com v 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 More free ebooks : http://fast-file.blogspot.com ■ CONTENTS vi 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 More free ebooks : http://fast-file.blogspot.com ■ CONTENTS vii ■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 More free ebooks : http://fast-file.blogspot.com ■ CONTENTS viii 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 More free ebooks : http://fast-file.blogspot.com [...]... Introduction What the book is about jQuery a rich bundle of JavaScript libraries that helps users apply dynamic functionality to web pages with great ease jQuery provides several powerful features, including the ability to access a part of a web page, modify the content on fly, add animation, apply AJAX, and more This book uses a problem-solution approach to understanding the wide features provided... Communication Protocols testing tools and methodologies, and has been developing Internet and mobile applications in many programming languages, with many evolving Massimo Nardone works as Technical Reviewer in many different IT areas, including security, wwwtechnology, and database He researched, designed, and implemented security methodologies for Standard BS7799, PKI and WPKI, Security Java (JAAS, JSSE,... apply effects to paragraphs and lists, we learn how to set the layouts of a web page After that, we cover techniques involved in event handling, followed by performing validations to different form elements Applying visual effects, navigations, AJAX and many more facets of jQuery are also explained in the form of recipes The coding used in all the recipes is completely explained with screen shots at... install jQuery so you can use it in your application and follow the recipes in this book 1 More free ebooks : http://fast-file.blogspot.com CHAPTER 1 ■ JQUERY BASICS Solution jQuery comes as a single js (JavaScript) file and it is very easy to download and install jQuery in any web application Download the latest version of jQuery from its official site: http:/ /jquery. com/ This book uses version jquery- 1.3.2... for doing a great job, and for her sincere efforts with the whole team to get the book published on time A great big thank you to the editorial and production staff and the entire team at Apress who worked tirelessely to produce this book Really, I enjoyed working with each of you I am also thankful to my family – my small world: Anu (my wife) and my two little darlings: Chirag and Naman for allowing... an opportunity to create this work I am highly grateful to the whole team at Apress for their constant cooperation and contribution to the creation this book My gratitude goes out to Matthew Moodie who, as a Development Editor, offered a significant amount of feedback that helped to improve the chapters He played a vital role in improving the structure and quality of the information I must thank Massimo... Programming (CBC, 2006), Business Systems (CBC, 2006), Practical Java Project (Shroff, 2007), Practical Web Services (Shroff, 2007), Java for Professionals (Shroff, 2008), C++ for Beginners (Shroff, 2009), Practical ASP.NET 3.5 Projects (Shroff, 2009), Java Server Faces - A Practical Approach for Beginners (PHI Learning, 2009), Practical JSF Project using NetBeans (PHI Learning, 2009), Foundation Joomla... select all the paragraph elements and call the addClass() method on them This will apply the CSS class highlight to all the paragraphs in the document 1-3 Delaying the Execution of JavaScript Problem A JavaScript file referenced in the head section of the HTML file is executed as soon as the browser finds the script line, but there are no HTML elements to which the styles can be applied (because the JavaScript... learn from this book • • • • • • • • • Applying effects to Paragraphs and Lists Setting Layouts Event Handling Form Validation Page Navigations Visual Effects Dealing with Tables AJAX Using Plug ins xxxi More free ebooks : http://fast-file.blogspot.com CHAPTER 1 ■■■ jQuery Basics In this chapter, we will be dealing with the basics of jQuery, from installing it to working with DOM nodes These fundamental... both national and international projects, Nardone has been working as a Project Manager, Software Engineer, Research Engineer, Chief Security Architect and Software Specialist He also worked as Visiting lecturer and supervisor for exercises at the Networking Laboratory of the Helsinki University of Technology (TKK) for the course of "Security of Communication Protocols" Nardone is very familiar with . Recipes A Problem-Solution Approach B.M. Harwani An expert compilation of solutions to real-world jQuery problems THE APRESS ROADMAP jQuery Recipes Practical JavaScript Projects Beginning JavaScript. 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. information on translations, please e-mail info @apress. com, or visit http://www .apress. com. Apress and friends of ED books may be purchased in bulk for academic, corporate, or promotional use.