Home >>jQuery Tutorial >jQuery click() Events
jQuery click() Events in jQuery is used to triggers the click event, or attaches a function to run when a click event occurs, it occurs when element is clicked.
Syntax:
Trigger the click event for the selected elements: | $(selector).click() |
Attach a function to the click event: | $(selector).click(function) |
Parameter | Description |
---|---|
function | It is optional and is used to Specifies the function to run when the click event occurs |
Here is an Example of jQuery click() Method:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".txt").click(function(){
alert(" paragraph was clicked :)");
});
});
</script>
</head>
<body>
<p class="txt">Click Here!!!!</p>
</body>
</html>
Click Here!!!!