Book Image

jQuery 2.0 Development Cookbook

By : Leon Revill
Book Image

jQuery 2.0 Development Cookbook

By: Leon Revill

Overview of this book

Table of Contents (17 chapters)
jQuery 2.0 Development Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Detecting element clicks


Having the ability to detect if a user has clicked on elements other than buttons can provide additional flexibility to your web application. You can attach click events to any HTML elements, just as we did with the buttons in the previous recipe.

Getting ready

To work through this recipe, we are first going to need a blank HTML page named recipe-2.html, the same as in the other recipes. Remember that you need to have the latest version of jQuery downloaded and easily accessible on your computer so that it can be included in recipe-2.html.

How to do it…

To understand how you can detect user clicks on elements other than buttons, perform the following steps:

  1. Add the following HTML to the recipe-2.html page you have just created. This HTML creates a very basic web page with an input, an anchor, and a division element.

    <!DOCTYPE html>
    <html>
    <head>
        <title>Chapter 2 :: jQuery Events</title>
        <script src="jquery.min.js"></script...