jQuery
Pocket Primer
LICENSE, DISCLAIMER OF LIABILITY, AND LIMITED WARRANTY
By purchasing or using this book (the Work), you agree that this license grants permission to use the contents contained herein, but does not give you the right of ownership to any of the textual content in the book or ownership to any of the information or products contained in it. This license does not permit uploading of the Work onto the Internet or on a network (of any kind) without the written consent ofthe Publisher. Duplication or dissemination of any text, code, simulations, images, etc. contained herein is limited to and subject to licensing terms for the respective products, and permission must be obtained from the Publisher or the owner of the content, etc., in order to reproduce or network any portion of the textual material (in any media) that is contained in the Work.
M ERCURY L EARNING AND I NFORMATION (MLI or the Publisher) and anyone involved in the creation, writing, or production of the companion disc, accompanying algorithms, code, or computer programs (the software), and any accompanying Web site or software of the Work, cannot and do not warrant the performance or results that might be obtained by using the contents of the Work. The author, developers, and the Publisher have used their best efforts to insure the accuracy and functionality of the textual material and/or programs contained in this package; we, however, make no warranty of any kind, express or implied, regarding the performance of these contents or programs. The Work is sold as is without warranty (except for defective materials used in manufacturing the book or due to faulty workmanship).
The author, developers, and the publisher of any accompanying content, and anyone involved in the composition, production, and manufacturing of this work will not be liable for damages of any kind arising out of the use of (or the inability to use) the algorithms, source code, computer programs, or textual material contained in this publication. This includes, but is not limited to, loss of revenue or profit, or other incidental, physical, or consequential damages arising out of the use of this Work.
The sole remedy in the event of a claim of any kind is expressly limited to replacement of the book, and only at the discretion of the Publisher. The use of implied warranty and certain exclusions vary from state to state, and might not apply to the purchaser of this product.
jQuery
Pocket Primer
Oswald Campesato
Copyright 2015 by M ERCURY L EARNING AND I NFORMATION LLC. All rights reserved.
This publication, portions of it, or any accompanying software may not be reproduced in any way, stored in a retrieval system of any type, or transmitted by any means, media, electronic displayor mechanical display, including, but not limited to, photocopy, recording, Internet postings, or scanning, without prior permission in writing from the publisher.
Publisher: David Pallai
M ERCURY L EARNING AND I NFORMATION
22841 Quicksilver Drive
Dulles, VA 20166
info@merclearning.com
www.merclearning.com
(800) 232-0223
O. Campesato. jQuery Pocket Primer.
ISBN: 978-1-938549-14-4
The publisher recognizes and respects all marks used by companies, manufacturers, and developers as a means to distinguish their products. All brand names and product names mentioned in this book are trademarks or service marks of their respective companies. Any omission or misuse (of any kind) of service marks or trademarks, etc. is not an attempt to infringe on the property of others.
Library of Congress Control Number: 2013944477
1516321 Printed in the United States of America
This book is printed on acid-free paper.
Our titles are available for adoption, license, or bulk purchase by institutions, corporations, etc.
For additional information, please contact the Customer Service Dept. at 800-232-0223(toll free).
All of our titles are available in digital format at authorcloudware.com and other digital vendors. Companion files (figures and code listings) for this title are available by contacting info@merclearning.com. The sole obligation of M ERCURY L EARNING AND I NFORMATION to the purchaser is to replace the disc, based on defective materials or faulty workmanship, but not based on the operation or functionality of the product.
Id like to dedicate this book to my parents
may this bring joy and happiness into their lives.
This book endeavors to provide you with as much up-to-date information as possible regarding jQuery that can be reasonably included in a book consisting of roughly 200 pages. You need some familiarity with HTML Web pages and JavaScript, but no prior knowledge of jQuery is required.
Which Version of jQuery is for this Book?
The code samples in this book were initially written using jQuery 1.7.1. These code samples were upgraded to jQuery 2.0 beta, along with jQuery Migrate plugin (version 1.9.1) to ensure that the code samples do not contain any deprecated jQuery methods.
There are two benefits to this approach. First, you can use these HTML Web pages with jQuery 2.0 beta and be assured that they do not contain any deprecated jQuery code. In addition, if you need to use a version of jQuery prior to version 2.0 (perhaps due to an existing code base), these HTML Web pages work correctly without modification.
What About jQuery 2.0?
The current production version of jQuery is version 1.9, and jQuery 2.0 beta is also available. As this book goes to print, jQuery 2.0 will probably become available as well. The key point to remember is that jQuery 2.0 removes support for IE 6, IE 7, and IE 8, and also deprecates some jQuery methods that are available in earlier versions of jQuery. Fortunately, version 2.0 will be backward compliant with jQuery 1.9.
Which Version of jQuery Should Readers Use?
This is an important question because there are at least five active versions of jQuery in HTML Web pages (back to version 1.6.x). The answer is simple: strive to write code that is compliant with jQuery 2.0.
There are two things that you can do to achieve jQuery 2.0 compliance. First, make sure that you do not use the jQuery methods that have been desupported, which are available here (along with other changes):
http://jquery.com/upgrade-guide/1.9/
Second, use the jQuery Migrate plugin, which you can use with either 1.9 or 2.0 to detect deprecated and removed features, or to restore old features for cases where you need old code to run with new jQuery. The plugin and the messages it generates are documented in the project README.
You can use the plugin simply by including it after your jQuery file and check for warning messages regarding deprecated code. For example, if you plan to use jQuery 1.9 in your HTML Web pages, include the following code snippet:
If you plan to use jQuery 2.0 in your HTML Web pages, include the following code snippet:
When you add the preceding code snippet to an HTML Web page and then launch that Web page in a WebKit-based browser, you will see the following message in the Inspector if there are no errors:
JQMIGRATE: Logging is active
You can find additional details on the jQuery blog:
http://blog.jquery.com/
How Do I Actually Find the Deprecated Code?
Launch the HTML Web page in question in a WebKit-based browser and open the Web Inspector to check for errors or warnings. Unfortunately, the jQuery Migrate plugin can generate warning messages that are unintuitive. For example, consider the following code snippet in JQDragAndDrop1.html in Chapter 5:
Next page