Changing jquery input field even when changing value through jquery

I am trying to capture when the value of a text input field changes. I use:

$("input[name=color]").change(function(){

This works if I type a new value directly. However, the value of the input field is changed using jquery. There are several such fields, and I need to know when they changed. Is there any way to detect this change?

Sorry, I was not clear. I am not the one who changes the meaning. This is an addon that I would prefer not to change if I need to transfer it to another project.

bypass

Okay, so you cannot do what I wanted to do, but here is the work. I just took a break and changed the event changeto event each.

setInterval(function(){
    $("input[name=color]").each(function(){ my code })
},100);
+5
source share
4 answers

, .

change , .

$("input[name=color]").val("newValue").change();
+11

jquery jquery after

$("input[name=color]").val('someValue').trigger('change');
+2

No, the onchange event will not be fired when the value is changed using javascript. Alternatively, you can trigger the onchange event when you change the value.

+1
source

One option is to track a value outside your listener’s area.

function foo () {
  var value = null;
  $("select#thingy").on("change", function (e) {
    let p = $(this).children("#choose-me").val();
    value = value === p ? null : p;
    $(this).val(value);
  });
}

$(function() {
  foo();
})
0
source

All Articles