Detect changes in text field.

Demonstrates how changes in a text field can be detected and spurious events filtered out.

by lddubeau

HTML

<input id="text" type="text"></input>

JavaScript

$(function () {
    $("#text").on("keyup change input propertychange", (function () {
        var val = "";
        return function (ev) {
            console.log("TYPE:", ev.type);
            var new_val = $(this).val();
            if (new_val !== val) {
                console.log("CHANGED:", val, "->", new_val);
                val = new_val;
            }
        };
    })());
});