jQuery: Novice to Ninja
by Earle Castledine and Craig Sharkie
Copyright 2012 SitePoint Pty. Ltd.
Product Manager: Simon Mackie
Technical Editor: Tom Museth
Expert Reviewer: Jrn Zaefferer
Editor: Kelly Steele
Assistant Technical Editor: Diana MacDonald
Indexer: Michele Combes
Cover Designer: Alex Walker
Notice of Rights
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means without the prior written permission of the publisher, except in the case of brief quotations included in critical articles or reviews.
Notice of Liability
The authors and publisher have made every effort to ensure the accuracy of the information herein. However, the information contained in this book is sold without warranty, either express or implied. Neither the authors and SitePoint Pty. Ltd., nor its dealers or distributors, will be held liable for any damages to be caused either directly or indirectly by the instructions contained in this book, or by the software or hardware products described herein.
Trademark Notice
Rather than indicating every occurrence of a trademarked name as such, this book uses the names only in an editorial fashion and to the benefit of the trademark owner with no intention of infringement of the trademark.
Published by SitePoint Pty. Ltd.
48 Cambridge Street Collingwood VIC Australia 3066
Web: www.sitepoint.com
Email: business@sitepoint.com
About Earle Castledine
Sporting a Masters in Information Technology and a lifetime of experience on the Web of Hard Knocks, Earle Castledine (aka Mr. Speaker) holds an interest in everything computery. Raised in the wild by various 8-bit home computers, he settled in the Internet during the mid-nineties and has been living and working there ever since. A senior systems analyst and JavaScript flneur, he is equally happy in the rapid rivers of Scala, the dense foliage of mobile apps and games, or the fluffy clouds of client-side interaction development. As co-creator of the client-side opus TurnTubelist, as well as countless web-based experiments, Earle recognizes the Internet not as a lubricant for social change but as a vehicle for unleashing frivolous ECMAScript gadgets and interesting time-wasting technologies.
About Craig Sharkie
A degree in Fine Art is a strange entrance to a career with a passion for programming, but thats where Craig started. A right-brain approach to code and problem-solving has seen him plying his craft in many of the big names of the Web: AOL, Microsoft, Yahoo, Ziff-Davis, and Australias Atlassian. Today, youll find him coding HTML5 and JavaScript solutions for Telstra Medias IPTV division, stretching the boundaries of where you might expect to find jQuery. His passion for programming and a fondness for serial commas and the like have led him on a path from journalism, through development, on to conferencing, and now into print. Taking up JavaScript in 1995, he was an evangelist for the good parts even before Crockford coined the term, and has seen the language flow from the desktop through mobile, and out to televisions and beyond. Being able to start the day with his new daughter just makes seeing where each day leads all the more fascinating.
About Tom Museth
Tom Museth first fell in love with code while creating scrolling adventure games in BASIC on his Commodore 64, and usability testing them on reluctant family members. He then spent 16 years as a journalist and production editor before deciding web development would be more rewarding. He has a passion for jQuery, PHP, HTML5, and CSS3; is eagerly eyeing the world of mobile dev; and likes to de-stress via a book, a beach, and a fishing rod.
About Jrn Zaefferer
Jrn Zaefferer is a freelance web developer, consultant, and trainer, residing in Cologne, Germany. Jrn evolved jQuerys test suite into QUnit, a JavaScript unit-testing framework, and maintains it. He also created and maintains a number of popular plugins. As a jQuery UI development lead, he focuses on the development of new plugins, widgets, and utilities.
About SitePoint
SitePoint specializes in publishing fun, practical, and easy-to-understand content for Web professionals. Visit http://www.sitepoint.com/ to access our blogs, books, newsletters, articles, and community forums.
Preface
No matter what kind of ninja you area cooking ninja, a corporate lawyer ninja, or an actual
ninja ninjavirtuosity lies in first mastering the basic tools of the trade. Once conquered, its then up to the full-fledged ninja to apply that knowledge in creative and inventive ways. In recent times, jQuery has proven itself to be a simple but powerful tool for taming and transforming web pages, bending even the most stubborn and aging browsers to our will. jQuery is a library with two principal purposes: manipulating elements on a web page, and helping out with Ajax requests. Sure, there are quite a few commands available to do this, but theyre all consistent and easy to learn. Once youve chained together your first few actions, youll be addicted to the jQuery building blocks, and your friends and family will wish youd never discovered it! On top of the core jQuery library is jQuery UI: a set of fine-looking controls and widgets (such as accordions, tabs, and dialogs), combined with a collection of full-featured behaviors for implementing controls of your own. jQuery UI lets you quickly throw together awesome interfaces with little effort, and serves as a great example of what you can achieve with a little jQuery know-how. At its core, jQuery is a tool to help us improve the usability of our sites and create a better user experience.
Usability refers to the study of the principles behind an objects
perceived efficiency or elegance . Far from being merely flashy, trendy design, jQuery lets us speedily sculpt our pages in ways both subtle and extreme: from finessing a simple sliding panel to implementing a brand-new user interaction you invented in your sleep. Becoming a ninja isnt about learning an API inside out and back to front; thats just having a good memory. The real skill and value comes when you can apply your knowledge to making something exceptional: something that builds on the combined insights of the past to be even slightly better than anything anyone has done before. This is certainly not easy, but thanks to jQuery, its fun just trying.