Example of click event usage in jQuery

  • 2020-05-09 18:07:03
  • OfStack

This article illustrates the use of click events in jQuery as an example. Share with you for your reference. The specific analysis is as follows:

The click event is triggered when the mouse pointer is over the matching element, then the left mouse button is pressed and released, or the click() method is called.

A complete event process, not only has to be able to trigger the event conditions, but also has an event handler.

You can bind event handlers for click events using the click() method. Such as:

$("button").click(function(){$("div").css("color","green")})

The code above binds the function function as an event handler to the click event via the click() method. This function is called when the click event is triggered.

Example code:


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title>click The event - The home of the script </title>
<style type="text/css">
div{
  width:100px;
  height:100px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){$("div").css("color","green")})
})
</script>
</head>
<body>
<div> The test script </div>
<button> Click to view </button>
</body>
</html>

In the above code, click the button to set the font color in div to green.

I hope this article is helpful for you to design jQuery program.


Related articles: