Aside from your typos, you need to always run the $("#word-count").text(stuff);
part. Here's it working without the else
:
var w_limit = 20;
$(document).ready(function () {
$('#comment').keyup(function (e) {
var el = $(this),
val = el.val();
if (val.length >= w_limit){
el.val( val.substr(0, w_limit) );
}
$("#word-count").text(w_limit - el.val().length + ' characters left');
});
});
DEMO: http://jsfiddle.net/eHstm/
(of course, I used a lower w_limit
number for testing purposes)