The problem is in how you're applying the decrement operator. If you
put it at the end of the number, as in:

number--

Then, the current number will be returned, THEN decremented. That's
what's happening here.

Simply put the operator before the number, so it is decremented THEN
returned.

$('.number').html( --count );

On Aug 3, 4:15 pm, littlerobothead <nickmjo...@gmail.com> wrote:
> I have a status area in an app I'm working on. It shows the number of
> unread alerts. As the user clicks each alert, it's subtracted from the
> total. The following code counts the number of items to use as my
> total:
>
> var trigger = $("#dataset-b tr.unread");
>         var count = $(trigger).length;
>         $(".number").html(count);
>
> And then this works to subtract from that number on each click:
>
>         $(trigger).click(function(){
>                 $(".number").html(count--);
>                 if (count == 0){
>                         $(trigger).unbind("click");
>                 }
>                 $(this).removeClass('unread');
>         });
>
> Problem is, nothing happens on the first click. However, on the second
> click my number starts to decrement. What's going on here? How can I
> make the count work?
>
> Best,
> Nick

Reply via email to