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>
2

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you ! I m doing it for d first tym so kinda new to things here !
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

1 Comment

Thank you!I messed it up der !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.