O'Reilly logo

Mastering jQuery by Alex Libby

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required