Wednesday, 15 September 2010

jquery - on('click') doesn't work after off('click') -



jquery - on('click') doesn't work after off('click') -

the next code doesn't work. removes class disabled, divs not 1 time again clickable. mean function works once.

$(document).ready(function(){ $('div.downloadbutton').on('click', function(e) { $('div.downloadbutton').off('click'); $('div.downloadbutton').not(this).addclass('disabled', {duration:500}); settimeout(function(){ $('div.downloadbutton').on('click'); $('div.downloadbutton').not(this).removeclass('disabled', {duration:500}); }, 3000); }); });

rather binding/unbinding event handlers, seek having state variable can command logic with. this:

var clickdisabled = false; // initial state; allow click $('div.downloadbutton').on('click', function(e) { if (!clickdisabled) { $('div.downloadbutton').not(this).addclass('disabled', { duration:500 }); clickdisabled = true; settimeout(function() { clickdisabled = false; }, 3000); }; });

example fiddle

jquery

No comments:

Post a Comment