click() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:click

jQuery click() Method

Description

The click() method triggers the click event, or sets a function as click event handler.

Syntax

$(selector).click(function);
Parameter Description
function Optional. Specifies the function to run when the click event occurs

The following code shows how to Click on a <p> element to alert a text:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("p").click(function(){
        console.log("The paragraph was clicked.");
    });//from  ww  w.j  av a2  s.  co  m
});
</script>
</head>
<body>

<p>Click on this paragraph.</p>

</body>
</html>

Related Tutorials