Sunday, May 12, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  14] [ 4]  / answers: 1 / hits: 67879  / 9 Years ago, tue, november 24, 2015, 12:00:00

I want to fire the JQuery change event when the input text is changed programmatically, for example like this:





$(input).change(function(){
console.log(Input text changed!);
});
$(input).val(A);

<script src=https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js></script>
<input type='text' />





But it doesn't work. How can I make this work?


More From » jquery

 Answers
12

change event only fires when the user types into the input and then loses focus.




You need to trigger the event manually using change() or trigger('change')





$(input).change(function() {
console.log(Input text changed!);
});
$(input).val(A).change();

<script src=https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js></script>
<input type='text' />




[#64295] Friday, November 20, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
angelicajayleneh

Total Points: 216
Total Questions: 110
Total Answers: 100

Location: Sudan
Member since Tue, Aug 3, 2021
3 Years ago
;