The jQuery change() is an inbuilt method that is used to detect the change in the value of input fields. This method works only on the “<input>, <textarea> and <select>” elements.
Syntax :
$(selector).change(function)
Parameter: It accepts an optional parameter “function”.
jQuery examples to show the working of change() method:
Example 1: In the below code, no function is passed to the change method.
HTML
<!DOCTYPE html>
<html>
<head>
<script src=
</script>
<script>
$(document).ready(function () {
$("button").click(function () {
$("input").change();
});
});
</script>
</head>
<body>
<p>Click the button to see the changed value !!!</p>
<button>Click Me!</button>
<p>Enter value:
<input value="GeeksforGeeks"
onchange="alert(this.value)"
type="text">
</p>
</body>
</html>
|
Output:

Example 2: In the below code, function is passed to the change method.
HTML
<!DOCTYPE html>
<html>
<head>
<script src=
</script>
<script>
$(document).ready(function () {
$(".field").change(function () {
$(this).css("background-color", "#7FFF00");
});
});
</script>
<style>
.field {
padding: 5px;
}
</style>
</head>
<body>
Enter Value:
<input class="field" type="text">
<p>
Write something in the input field, and then
press enter or click outside the field.
</p>
</body>
</html>
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Jul, 2023
Like Article
Save Article