esskay
esskay

Reputation: 43

How enable an default disabled button in Bootstrap?

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>

Upvotes: 2

Views: 2589

Answers (2)

Rahul
Rahul

Reputation: 685

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

Upvotes: 1

Crix
Crix

Reputation: 84

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.

Upvotes: 2

Related Questions