Javascript examples for jQuery Method and Property:click
The click() method triggers the click event, or sets a function as click event handler.
$(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:
<!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>