Adding Mouse-Click-Handling Code

$("p").on("click", function (e){   $(this).html("You clicked here."); }); $("span").on("dblclick", function (e){   $(this).html("You double-clicked here."); });

To register a click handler in jQuery, you should use the .on("click") or .on("dblclick") method. Inside the handler function, you can perform whatever event functionality your application requires. It is easy to apply the click handler to multiple objects using jQuery selectors. For example, the following applies a click handler to all <div> elements:

$("div").on("click", function (e){   $(this).html("You clicked here."); });

Get jQuery and JavaScript Phrasebook 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.