Reputation: 1485
My simple jQuery keypress script is not working. All i want to do is capture the input on a textarea (id = story) and log the key that was pressed to the console. I want the character logged to the console to be the actual character that was pressed as opposed to the keycode. I had some confusion between keyup and keypress events, but i have tried both, and i constructed the code below based on the jQuery documentation.
<script>
$('#story').keypress(function()
{
var txtInput = this.value;
console.log(txtInput);
});
</script>
Upvotes: 0
Views: 3631
Reputation: 10258
Try this
$(document).ready(function() {
$('#story').keyup(function()
{
var txtInput = $(this).val();
txtInput = txtInput.charAt(txtInput.length-1);
alert(txtInput);
});
});
Upvotes: 1