Hi all. I have already gotten some good help on a piece of code I'm struggling with. Hopefully someone can help me again. I have code which shows a checkmark next to an item 5 seconds after it's clicked. The problem: I need to cancel the checkmark popping up if the user is rapidly clicking links. Here's the demo:
Here's the code. I've gotten some help on this one from a few folks, but the Timeout still isn't working:
$(function() {
var thetimeout=null;
$('li a').click(function() {
$('li').not('this').css('background-position','left bottom');
$(this).parent().css('background-position','left top');
if(thetimeout!=null) {
window.clearTimeout(thetimeout);
}
var thetimeout=window.setTimeout($.proxy(function() {
$(this).parent().css('background-image','url(images/check.png)');
}, this)
,5000);
});
});
The clearTimeout should cancel the Timeout for all unclicked elements but it isn't working...any ideas?