jQuery click()

The jQuery click () method is executed once the click event occurs.

Syntax:

To trigger the click event for the selected elements.

$(selector).click()  

To attach a function to the click event.

$(selector).click(function)  

Example 1

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script>
$(document).ready(function(){  
	$("h1,h2").click(function(){  
    	$(this).hide();  
	});  
});  
</script>  
</head>  
<body>  
<h1>Click me. I am a ghost.</h1>  
<h2>Me too.</h2>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Example 2

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
	$("button").click(function(){  
     	alert("Width: " + $("div").width());  
	});  
});  
</script>  
</head>  
<body>  
<div style="height:100px;width:500px;padding:10px;margin:3px;border:1px solid blue;background-color:lightpink;"></div><br>  
<button>Width</button>  
</body>  
</html>

Try it

JS Bin on jsbin.com

Please Share