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

Creating a basic monkey patch


"A personality change?" I hear you ask. Yes, that's right; our dog seems to like miaowing…. (I can't think of a reason why; I don't know of any that would!)

In our example, we're going to use a simple click handler to prove that (in some cases) our dog can meow; we will then work through what is required in order to persuade it to do what it should do.

  1. Let's start by cracking open a text editor of our choice and then adding the following markup as a basis for our patch:

    <!DOCTYPE html>
    <head>
      <title>Demo: Basic Duck Punching</title>
      <meta charset="utf-8">
      <script src="js/jquery.min.js"></script>
      <script src="js/duck.js"></script>
    </head>
    <body>
      <div>Hello World</div>
      <button>Make it a dog!</button>
    </body>
    </html>
  2. Save it as the duck.html file. In a separate file, we need to animate our button, so let's first add in a simple event handler for this purpose...