1

I have a problem with jQuery.

I have such small function

setTimeout(player_attack,500);
setTimeout(mob_attack,700);

This is triggered by button. But there is a problem. User can click it quickly and its all messing up. So i want to disable button for a while.

But this:

$('#button_name').attr("disabled","disabled");

but it works.

But when I put:

$('#button_name').removeAttr("disabled","disabled");

it doesnt work anymore.

Any suggestion?

  • 1
    Should $('#button_name').removeAttr("disabled","disabled"); be $('#button_name').removeAttr("disabled"); For removeAttr you shouldn't need to specify a value, just an attribute. – bygrace Aug 30 '12 at 18:19

4 Answers4

2

try this

$('#button_name').removeAttr("disabled");
alessio271288
  • 348
  • 1
  • 7
  • $(document).ready(function() { $('#Atakuj').bind('click', function() { $("#Atakuj").prop("disabled", true); setTimeout(player_attack,500); setTimeout(mob_attack,700); $("#Atakuj").prop("disabled", false); $('#messages').prepend('
    '); This doesnt want to work still
    – Tomasz Frydrychowicz Aug 30 '12 at 18:34
1

It is easier to use prop method:

$("#button_name").prop("disabled", false); // or true to make it disabled
VisioN
  • 143,310
  • 32
  • 282
  • 281
0

Just use:

$("#selector").attr("disabled", true); // or false

See this fiddle.

Josh
  • 12,448
  • 10
  • 74
  • 118
0

The jQuery docs recommend using the .prop() method rather than .attr() for changing the disabled property. (See here for more details.)

$('#button_name').prop("disabled", true); //or false
Mac Attack
  • 952
  • 10
  • 21
  • 1
    And here is a good reference on it. I was just looking into what was better: http://stackoverflow.com/questions/5874652/prop-vs-attr – bygrace Aug 30 '12 at 18:25