There's 3 ways to implement it.
The first way is using other event such as input
or propertychange
. Notice that propertychange
is supported only on IE and input
is supported on modern browsers.
$('#query').on('input perpertychange', function () {
console.log($(this).val());
});
The second way is putting console.log($(this).val());
in setTimeout
statement. You can get what you're typing. (The reason? I'm sorry, I really dont know why, just use it);
$('#query').keydown(function () {
var query = $(this);
setTimeout(function () {
console.log(query.val());
}, 0);
});
And the last one is using textchange
event (http://zurb.com/playground/jquery-text-change-custom-event). Like this:
$('#query').on('textchange', function () {
console.log($(this).val());
});