jQuery click() Method
jQuery click() method trigger the click event. The jQuery click event occurs when an element is clicked. And when the click event occurs, specified function will execute.
Syntax
This syntax represent to the click event trigger
$(selector).click(); // This syntax does not accept any arguments.
and this syntax represent to attach a function to the click event
$(selector).click(function);
Parameter | Type | Description |
---|---|---|
function | Function | Optional. Specifies the function to execute when the click event is occurs. |
Examples
This example represent to the click event trigger on the selected elements.
$(document).ready(function(){
$("button").click(function(){
$("p").click();
});
$("p").click(function(){
$("span").fadeIn(500);
$("span").fadeOut(500);
});
});
This example represent to attach a function to the click event.
$(document).ready(function(){
$("p").click(function(){
$("span").fadeIn(500);
$("span").fadeOut(500);
});
});