I am trying to implement the following in coffeescript/jquery
-> When user is typing, check that if the textBox is empty (or has text “Write a comment…”), hide the ‘add comment’ button. Else show the ‘add comment’ button


However, I am facing the issue whereby the val() returned to me from the textbox is always one keystroke behind.
For example, if I type ‘sad’ in the box, the target.val() returns me only ‘sa’.

How do I get the most updated value in the text box as I type?
My implementation as below
events:
"keydown .comment_area": "commenting"
commenting: (e) ->
target = @$(e.currentTarget)
//target.val() is not returning me the latest character entered in the box
if $.trim(target.val()) == "" or $.trim(target.val()) =="Write a comment..."
//hide the 'add' button
@$('.add_comment').hide()
else
//show the 'add' button
@$('.add_comment').show()
Bind to the
keyupevent instead ofkeydown.See the keyboard event order.