0

I need to enable a button "Save" when I click on "Edit". I am trying it like below, but nothing happens:

$(document).ready(function() {
  $("#btnEdit").click(function() {
    $("btnSave").removeProp("disabled");

  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modal-footer">
  <button id="btnEdit" type="button" class="btn btn-danger mt-4">Edit</button>
  <button id="btnSave" type="submit" class="btn btn-success mt-4" disabled>Save</button>
</div>

2 Answers 2

3

You need to use removeAttr(), not removeProp(). Or you can use .prop("disabled", false) to change the state of the property, which overrides the attribute.

You also had a typo: $("btnSave") is missing the #.

$(document).ready(function() {
  $("#btnEdit").click(function() {
    $("#btnSave").removeAttr("disabled");

  });
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modal-footer">
  <button id="btnEdit" type="button" class="btn btn-danger mt-4">Edit</button>
  <button id="btnSave" type="submit" class="btn btn-success mt-4" disabled>Save</button>
</div>

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

1 Comment

I did the corrections but did not work. Nothing happens. What could I be missing?
0

Try using

$(document).ready(function() {
  $("#btnEdit").click(function() {
    $("#btnSave").prop("disabled", false);
  });
});

You can also use functions instead of using the click event listener:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="modal-footer">
  <button id="btnEdit" onclick="disableButton(this)" type="button" class="btn btn-danger mt-4">Edit</button>
  <button id="btnSave" type="submit" class="btn btn-success mt-4" disabled>Save</button>
</div>

and

<script>
  function disableEl(el) {
      el.disabled = false;
  }
</script>

Comments

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.