Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   
   HTML   
   CSS   
   JAVA SCRIPT   
   JQUERY   




EVENTS - change()


The change() event is used to check if the contents of an element has changed or not.


Note : The 'change()' event is only applicable for <input>, <select> and <textarea> elements.

Example :



<html>
  	<head>
		<title> My First Programme </title>
		<script src = "https://cdnjs.cloudflare.com/ajax/libs/JQUERY/3.3.1/jquery.min.js"> </script>
  	</head>

  	<body>
    	<h1> JQuery </h1>
    		
    	Type Something then click outside : <input type = "text"> 		
	  
      	<script>
      		
			$('input').change( function() { 
        		$(this).css("background-color", "yellow")
        	});
        
      	</script>
  	</body>
</html> 


Output :



So, in the above code, we have an <input> element of type text.


<input type = "text">

And whenever we type something, and move the cursor outside the <input> element, the contents of the <input> element is changed and change() event is triggered.


$('input').change( function() {
	$(this).css("background-color", "yellow")
});

Changing the background color of the <input> element to yellow.