click()
click() event method will execute when the user clicks on the HTML DOM element.
#example.html
<!DOCTYPE html>
<html>
<head>
<title>Commonly Used jQuery Event Methods</title>
</head>
<body>
<p>If you click on me, I will disappear.</p>
<p>Click me too!</p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
//when you click p element it will disappear
$("p").click(function() {
$(this).hide();
});
});
</script>
</body>
</html>
$(document).ready()
The $(document).ready() method allows us to execute a function when the DOM is fully loaded.
Download source code
Are you facing problems in understanding this article? download source code now