1

I can't figure out why my button won't re-enable when another button is clicked. Any help will be most appreciated

My code is as follows:

$(document).ready(function() {
    $('#btnAdd').click(function() { 
        // enable the "remove" button
        $('#btnDele').attr('disabled','');
    }
});

demo here: http://jsfiddle.net/ATzBA/2/

random_user_name
  • 25,694
  • 7
  • 76
  • 115
user1038814
  • 9,337
  • 18
  • 65
  • 86
  • im assuming the lack of a second `}` is a typo? – Waltzy Jun 25 '12 at 20:46
  • try using removeAttr() instead of setting the attribute's value to an empty string – MrOBrian Jun 25 '12 at 20:48
  • @MrOBrian Don't use `removeAttr` on native properties, because once you do, they're gone and you cant work with them again till DOM refresh. – Ohgodwhy Jun 25 '12 at 20:50
  • @Ohgodwhy I've used `removeAttr` before for just this purpose and it works great in all browsers I've tested. If the element needs to be disabled again, a simple `attr('disabled', 'disabled')` adds the property back to the element – MrOBrian Jun 25 '12 at 20:55

6 Answers6

4
 $('#btnDele').attr('disabled',false);

should do the trick.

Waltzy
  • 1,113
  • 4
  • 14
  • 31
3

You could also try $("#btnDele").removeAttr('disabled');

johnmadrak
  • 840
  • 5
  • 7
3

The prop function is the correct way to do this in JQuery.

$('#btnDele').prop('disabled', false); //enabled
$('#btnDele').prop('disabled', true); //disabled
$('#btnDele').prop('disabled'); //returns true if disabled, false if enabled.

See documentation here.

jaypeagi
  • 3,133
  • 18
  • 33
2

The "disabled" attr has to be removed completely, not just set to null/an empty string. You need to use jQuery's removeAttr():

$(function(){
     $('#btnAdd').click(function(e){
          $(this).removeAttr('disabled');
      });
 });

Somebody talks about it/browser compatibility issues here: Toggle input disabled attribute using jQuery

Community
  • 1
  • 1
bokonic
  • 1,751
  • 10
  • 12
0

Instead of using the .attr function I'd use Jquery UI and use $('#btnDele').button("enable"); http://docs.jquery.com/UI/Button#methods

Alex Unger
  • 180
  • 2
  • 9
0

$(document).ready(function() { $('#btnAdd').click(function() {

        // to enable the "remove" button
        // set 'disabled to false'
        $('#btnDele').attr('disabled','false');

}); });

haroonxml
  • 356
  • 1
  • 3
  • 14