Why does object.observe not work for the value property of an input field?

625 Views Asked by At

I was playing with Object.observe in the latest version of Chrome and was wondering why it does not work for the 'value' property of a text input. The code below will log a change for adding/changing the 'foo' property, but not for changing the value property. Anybody know why?

var myTextInput = document.getElementById('myTextInput');

Object.observe(myTextInput, function(changes){

  changes.forEach(function(change) {
    console.log(change);
  });

});

myTextInput.value = 'test123';
myTextInput.foo = 'bar';
1

There are 1 best solutions below

1
On

I'm not sure why this is, but since you're observing a DOM element's attributes, the mutation observer api may be more appropriate.