It is possible to use Object.defineProperty()
in order to redefine the 'value' property of the input element and do anything during its changing.
Object.defineProperty()
allows us to define a getter and setter for a property, thus controlling it.
replaceWithWrapper($("#hid1")[0], "value", function(obj, property, value) {
console.log("new value:", value)
});
function replaceWithWrapper(obj, property, callback) {
Object.defineProperty(obj, property, new function() {
var _value = obj[property];
return {
set: function(value) {
_value = value;
callback(obj, property, value)
},
get: function() {
return _value;
}
}
});
}
$("#hid1").val(4);