How to remove disabled attribute using jQuery?


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>

Updated on: 18-Dec-2019

11K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements