2

I'm trying to make an button enabled which is by default disabled in bootstrap.

I have tried using remove class, prop(), and remove attr in jQuery but it does not seem to work.

Is there a way to enable it?

like :

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script>
$('#example').prop('disabled', false);
</script>
</head>
<body>
<button id="example" type="button" class="btn btn-default btn-disabled"disabled>Text</button>

</body>
</html>
esskay
  • 43
  • 6
  • 2
    Possible duplicate of [What is the easiest way to disable/enable buttons and links (jQuery + Bootstrap)](http://stackoverflow.com/questions/16777003/what-is-the-easiest-way-to-disable-enable-buttons-and-links-jquery-bootstrap) – James Taylor Mar 27 '16 at 05:24
  • Show your tried code? – Moumit Mar 27 '16 at 05:24

2 Answers2

2

The reason why this does not work is simple: the html-element is not loaded at the point the javascript code is executed. So, this code does not do anything.

Try something like this:

$(document).ready(function(){ // Makes your code load after the page is loaded.
   $('#example').prop('disabled', false);
   $('.btn-default').removeClass('btn-disabled');
});

Working example: https://jsfiddle.net/crix/nxLmkutq/

Hope this helps! Good luck.

Crix
  • 86
  • 3
1

I guess you don't need btn-disabled class as disabled attribute takes care of that unless you need any specific color or any other css styling

<button id="example" type="button" class="btn btn-default" disabled>Text</button>

$(document).ready(function(){
   $('#example').prop('disabled', false);
});

jsFiddle

Rahul
  • 685
  • 5
  • 15