The .click() method attaches an event handler to the "click" event of an HTML element.



A handler function will be assigned to the "click" event of the HTML element(s) specified by selector.


The following jQuery code will spawn a message box every time a paragraph in the document is clicked:

$("p").click(function() {
alert("Paragraph clicked!");


Interested in helping build Docs? Read the Contribution Guide or share your thoughts in this feedback form.

Learn JavaScript on Codecademy