-->

jQuery click() Method

By: Bipin C Mathew 10 months, 2 weeks ago

The click() is an inbuilt method in jQuery that triggers the click event or attach a function to run when a click event occurs.

Syntax:

$(selector).click() -Trigger the click event for the selected elements.

$(selector).click(function) -Attach a function to the click event.

Example:

<!doctype html>
	<html lang="en">
		<head>
			<meta charset="utf-8">
			<script src="https://code.jquery.com/jquery-3.4.1.js"></script>
			<script>  
				$(document).ready(function(){  
				    $("p").click(function(){  
						alert("This paragraph was clicked.");  
				    });  
				});  
			</script>   
		</head>
		<body>
			<p>Click Me.</p>  
		</body>
	</html>

In this example function is optional. It specifies the function to run when the click event occurs. 

Comments

Let us talk!

We take the vision which comes from dreams and apply the magic of science and mathematics, adding the heritage of our profession and our knowledge to create a design.