0

So i have this small code snippet and i'm trying to figure out how to get it to work. Basically what it does is when the button is clicked, it becomes disabled. At the same time it runs a timeout function that will re-enable the button after 3 seconds. I can't figure out how to get it to work! Everything else in the button function works fine except for this. I didn't post the entire code cause it's a lot. Variables are all declared and what not.

$("input[type=button]").attr("disabled", "disabled");
var enable_attk = function() {
    $("input[type=button]").attr("enabled", "enabled");     
    enable_timer = setTimeout(enable_attk, 3000);
}

        enable_attk();
Egahtrac
  • 85
  • 5
  • 1
    One thing - instead of using `attr` for disabling, use `prop`: `$("selector").prop("disabled", true);` – Ian Jun 12 '14 at 21:10
  • Here's an example of how I'd do it: http://jsfiddle.net/EN9r3/ – Ian Jun 12 '14 at 21:13
  • @Ian is there anything wrong with using attr? Will it cause problems in the code or is using prop just a more appropriate way to code this? – Egahtrac Jun 12 '14 at 21:15
  • It's easier just to read this: http://stackoverflow.com/questions/5874652/prop-vs-attr – Ian Jun 12 '14 at 21:17
  • 1
    @Ian ok nice, i just changed it over. Thanks for the help =D – Egahtrac Jun 12 '14 at 21:30

1 Answers1

1
$("input[type=button]").attr("disabled", "disabled");
setTimeout(function(){
    $("input[type=button]").removeAttr("disabled");     
}, 3000);

http://jsfiddle.net/zDDbR/

Trent
  • 1,280
  • 11
  • 12