views:

58

answers:

3

If i have a button pressed method like this:

$('#next').click(function () {
});

How can i stop this method being initiated whilst its running. Say the method takes 5 seconds to run and someone clicks it 3 seconds in it breaks so i want to make the div thats being clicked unclickable while the methods running.

+7  A: 
$('#next').click(function () { 
   $(this).attr("disabled", "disabled"); 
   stuffff
   $(this).attr("disabled", ""); 
});
Byron Cobb
Have you tested this? It doesn't work for me (in FF 3.6.6)
Bobby Jack
I'm not 100% sure if it makes a difference, but you could try $(this).attr("disabled", true); $(this).attr("disabled", false);
Byron Cobb
Ive being trying to use disabled but its not working.'#next' is a div, not a button. Is this the reason why its not working?
phil crowe
<div id="clickDiv" style=" background-color:Green"><br /><br /></div>$("#clickDiv").click(function () { $(this).attr("disabled",true); alert("here"); });This works for me - it alerts the message once, but is disabled after that.
Byron Cobb
+3  A: 

Replace the clicked link with <p>loading...</p>

Akku
Not sure why this only has two upvotes - really if you have something that takes a long time - you should be telling the user you're doing something. Simply ignoring the users input does not make for a good user experience in my opinion.
Streklin
A: 

You can use "disabled" to disable the button while your execution, as like byron said

praveenjayapal