Detecting button clicks

Clicking on website elements is a primary user interaction; therefore, detecting these clicks is a very fundamental aspect in creating interactive web applications. There are various ways in which jQuery developers can listen for certain button presses within their web page.

Getting ready

Using your favorite text editor or IDE, create a blank HTML page named recipe-1.html in an easily accessible location.

How to do it…

Create two buttons with click event handlers by performing the following steps:

  1. Add the following HTML code to recipe-1.html. Be sure to change the location of the jQuery library in the JavaScript file, pointing it to where the latest version of jQuery is downloaded on your computer.
    <!DOCTYPE html> <html> <head> ...

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.