How to remove disabled attribute using jQuery?

jQueryWeb DevelopmentFront End Technology

To remove disabled attribute using jQuery, use the removeAttr() method. You need to first remove the property using the prop() method. It will set the underlying Boolean value to false.

Example

You can try to run the following code to learn how to remove disabled attribute using jQuery:

Live Demo

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){

    $('.disabledCheckboxes').prop("disabled", true);
    $('.disabledCheckboxes').removeAttr("disabled");

    $(document).ready(function(){
        $('button').on('click', function() {
          if (this.hasAttribute("disabled")) {
             alert('The disabled attribute exists')
          } else {
             alert('The disabled attribute does not exist')
          }
        })
    });
 });
</script>
</head>
<body>
<input type="checkbox" class="disabledCheckboxes" disabled>
<input type="checkbox" class="disabledCheckboxes" disabled="disabled">
   <button class='button'>Result</button>
</body>
</html>
raja
Published on 15-Dec-2017 18:41:59
Advertisements