Tomasz Frydrychowicz
Tomasz Frydrychowicz

Reputation: 11

Disabling button usage with timeout functions

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?

Upvotes: 1

Views: 206

Answers (4)

Mac Attack
Mac Attack

Reputation: 962

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

Upvotes: 0

alessio271288
alessio271288

Reputation: 358

try this

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

Upvotes: 2

VisioN
VisioN

Reputation: 145478

It is easier to use prop method:

$("#button_name").prop("disabled", false); // or true to make it disabled

Upvotes: 1

Josh
Josh

Reputation: 12566

Just use:

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

See this fiddle.

Upvotes: 0

Related Questions