I\'m trying to detect whenever a form input\'s value changes using Javascript & JQuery. Unfortunately, I find JQuery\'s $(elem).change() insufficient becaus
You can monitor all the changes using MutationObserver. This won't give you event for every keydown and keyup, but it kind of consolidate multiple changes and give it out to you as single event.
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver || window.MozMutationObserver;
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
// mutation.target will give you element which has been modified.
// mutation.addedNodes and mutation.removedNodes will give you operations that were performed on the node
// happy coding :)
});
});
observer.observe(elementsToMonitor, {
attributes: true,
childList: true,
characterData: true
});
More info about MutationObserver https://developer.mozilla.org/en/docs/Web/API/MutationObserver