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