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

Get jQuery 2.0 Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.