Example of change event usage in jQuery

  • 2020-05-10 17:37:11
  • OfStack

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

The change event is triggered when the matching element loses focus or its value gains focus and changes.

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 change events through the change() method. Such as:

$("input").change(function(){$("input").css("backgroundColor","green")})

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


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//www.ofstack.com/" />
<title> The home of the script </title>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(document).ready(function(){
  $("input").change(function(){
    $("input").css("backgroundColor","green")
  })
})
</script>
</head>
<body>
<div><input type="text" name="content" /></div>
<div> Changing the text in the text box triggers an event </div>
</body>
</html>

I hope this article has helped you with the jQuery programming.


Related articles: