Book Image

Mastering jQuery

By : Alex Libby
Book Image

Mastering jQuery

By: Alex Libby

Overview of this book

<p>Mastering jQuery has been written not only to help maximize your skills with core functionality in the library, but also to explore some of the more intriguing ways of using the library to achieve real-world solutions that could feature on any website or online environment.</p> <p>You'll start with a look at some of the more advanced ways to incorporate the library into your pages, followed by working with forms and advanced form validation using regular expressions. Next you'll move on to animating in jQuery, advanced event handling, and using jQuery effects.</p> <p>Finally, you will develop practical examples of using jQuery with external functionality such as node-webkit, before finishing with a session on optimizing your version of the library for maximum efficiency and exploring best practices for using QUnit.</p>
Table of Contents (21 chapters)
Mastering jQuery
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introducing event handling


A question – how often do you go online to perform a task? I'll bet it's a fair few times a week; it could be anything from online banking, to hitting Amazon to get that latest DVD (DVDs – who downloads them, I wonder?)

That aside, we can't escape having to click on a link or a button to advance through a process. In most cases, the code behind the event is likely to be the ubiquitous click handler, or it could even be .change() or .hover(). All are shorthand forms of the .on() (or even .off()) event handlers, and are of course functionality equivalent to something like the following:

$('a').on('click', function(){
  $(this).css('background-color','#f00');
});

This will turn the selected element to a nice shade of red. However, there is more to event handling than simply defining an action on a known element. Over the next few pages, we're going (to quote a nautical term) to push the boat out, and take a look at a few tips and tricks that we can use, to help develop...