Attach a function to the change event - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:change

Description

Attach a function to the change event

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $(".field").change(function(){
        $(this).css("background-color", "#D6D6FF");
    });/*w w  w.  jav  a2 s.  c o m*/
});
</script>
</head>
<body>

Enter your name: <input class="field" type="text">

Car:
<select class="field" name="cars">
  <option value="a">a</option>
  <option value="b">b</option>
  <option value="c">c</option>
  <option value="d">d</option>
</select>

</body>
</html>

Related Tutorials