Run
Run

Reputation: 57176

How can I return click again after disabling it?

How can I return click again after disabling it?

For instance, when the page is loaded I want to turn off all clickable button on the menu,

$(".menu > ul > li > a").click(function(){return false;});

after 3 seconds later, I want to turn them back on, so I am doing this,

var timeout = setTimeout(function() {
     $(".menu > ul > li > a").click(function(){return true;});
}, 3000 ); 

it does not work of course! How can I fix this?

Upvotes: 1

Views: 202

Answers (2)

rainerhahnekamp
rainerhahnekamp

Reputation: 1136

Have you tried out

var timeout = setTimeout(function() {
 $(".menu > ul > li > a").unbind('click').click(function(){return true;});
}, 3000 ); 

Upvotes: 2

John Giotta
John Giotta

Reputation: 16944

You would be better off binding and unbinding the event handler

http://api.jquery.com/unbind/

var handler = function() {
    return false;
};
$(".menu > ul > li > a").bind('click', handler);
var timeout = setTimeout(function() {
    $(".menu > ul > li > a").unbind('click', handler);
}, 3000);

Upvotes: 3

Related Questions