开发者

Why doesn't my hide function work on a click [closed]

开发者 https://www.devze.com 2023-04-02 18:26 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to th开发者_运维知识库e worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 11 years ago.
$(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.

0

精彩评论

暂无评论...
验证码 换一张
取 消