$(document).ready(function() {
$('#promotion_profile_booking_description').keyup(function () {
var left = 200 - $(this).val().length;
if (left < 0) {
left = 0;
}
$('#counter').text('Characters left: ' + left);
});
$('#counter').bind('click', function() {
(this).hide();
});
});
The previous code essentially inserts "Characters left: x", as a text counter. It works great. However hiding the element on a click is another story. Why isn't my hide function working? Do you see any obvious errors in my JS?
Try changing (this).hide();
to $(this).hide();
Also Use a debugger my friend. It can help allot to figure out you have no errors in the script. With firefox you can easily pop up the javascript debugger by pressing Ctrl+Shift+J.
精彩评论