Description
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 occur.
Trigger the Event
Trigger the click event for the selected elements.
This method has the form:
.click()
Return Value
This form returns a jQuery object.
Bind a Function to the Event
Specifies a function to run when the click event occurs for the selected element.
This method has the alternate form:
.click(function)
Parameter | Description |
---|---|
function | (optional) Specifies the function to run when the click event occurs |
Return Value
This form returns a jQuery object.
This method has the alternate form:
.click(data,function)
Parameter | Description |
---|---|
data | (optional) Specifies additional data to pass along to the function |
function | (optional) Specifies the function to run when the click event occurs |
Return Value
This form returns a jQuery object.
Examples
Hide or show a p element when a button is clicked:
$("button").click(function(){
$("p").slideToggle();
});