Skip to content

Instantly share code, notes, and snippets.

@dznz
Created January 14, 2014 04:01
Show Gist options
  • Save dznz/8412835 to your computer and use it in GitHub Desktop.
Save dznz/8412835 to your computer and use it in GitHub Desktop.
Count down the number of characters that remain in a text box.
$ ->
$body = $('#question_body')
$counter = $('#js-body-count')
determineChange = ->
remainingChars = 140 - $body.val().length
if remainingChars isnt 140
$counter.text remainingChars
else
$counter.text ""
$body.keyup determineChange
$body.keypress (e) ->
setTimeout ->
determineChange
, 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment