Situatie
The change() is an inbuilt method in jQuery that is used to detect the change in value of input fields. This method works only on the “<input>, <textarea> and <select>” elements.
Solutie
Pasi de urmat
Syntax :
$(selector).change(function)
Parameter: It accepts an optional parameter “function”.
Return Value: It returns the element with the modification.
jQuery code to show the working of change() method:
Code #1:
In the below code, no function is passed to the change method.
<html>
<head>
<script src=”https://ajax.googleapis.com/ajax/libs/
jquery/3.3.1/jquery.min.js”></script>
<!–Demo of change method without passing function–>
<script>
$(document).ready(function() {
$(“button”).click(function() {
$(“input”).change();
});
});
</script>
</head>
<body>
<p>Click the button to see the changed value !!!</p>
<!–click on this button and see the change –>
<button>Click Me!</button>
<p>Enter value:
<input value=”Donald” onchange=”alert(this.value)”
type=”text”></p>
</body>
</html>
Leave A Comment?