jQuery click()Method

jQuery 事件方法jQuery Event Methods

Examples

Alert text when the <p> element is clicked:

$("p").click(function(){
alert("The paragraph was clicked.");
});

Try it yourself »

Definition and Usage

The click event occurs when an element is clicked.

The click() method triggers the click event, or specifies a function to run when a click event occurs.


Syntax

Trigger the click event for the selected elements:

$(selector).click() Try it yourself

Add a function to the click event:

$(selector).click(function) Try it yourself

Parameter Description
function Optional. Specifies a function to run when the click event occurs.


jQuery 事件方法jQuery Event Methods

Other Extensions