Created
May 16, 2013 10:11
-
-
Save castus/5590735 to your computer and use it in GitHub Desktop.
[js] A better onChange event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var input = jQuery("textarea"); | |
function logger() { console.log(Array.prototype.slice.call(arguments)); } | |
function okay(e) { | |
logger(e.keyCode, input.val()); | |
} | |
function better(e) { | |
setTimeout(function() { | |
logger(e.keyCode, input.val()); | |
}, 0); | |
} | |
// This only occurs when a key generates output | |
input.on("keypress", okay); | |
// Better, but some browsers don't implement it properly... | |
input.on("change", okay); | |
// This will give you the output instantly when any key is pressed | |
input.on("keydown", better); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment