0

I couldn't quite get it to work properly. I'm trying to remove the disabled attribute on click so that I can edit it.

My jQuery:

$('#edit-credentials').click(function() { 
    $('#credentials :input').prop("disabled", !$('#credentials:input').prop("disabled")) 
});

HTML:

<a id="edit-credentials" onclick="return false;" href="#">edit</a>

<div id="credentials">
<input disabled="disabled">
<input disabled="disabled">
</div>
2
  • Are you trying to toggle the disabled property?
    – Starx
    Apr 14, 2012 at 17:01
  • can you post the credentials part? also, just a guess- try to remove the return false bit..
    – J. Ed
    Apr 14, 2012 at 17:02

4 Answers 4

4

What wrong with

$('#credentials :input').prop("disabled", false);
1

You can remove disable attribute from input via

$('#credentials :input').removeAttr("disabled");
1
  • I read that prop() is the new attr() and that you should avoid attr() from now on.
    – Strawberry
    Apr 14, 2012 at 20:45
0

try this:

$("#edit-credentials").click(function() {
  $('#credentials :input').removeAttr("disabled");
});
2
  • I read that prop() is the new attr() and that you should avoid attr() from now on.
    – Strawberry
    Apr 14, 2012 at 20:45
  • "".attr() should not be used on plain objects, arrays, the window, or the document. To retrieve and change DOM properties, use the .prop() method. Using jQuery's .attr() method to get the value of an element's attribute has two main benefits: Convenience: It can be called directly on a jQuery object and chained to other jQuery methods. Cross-browser consistency: The values of some attributes are reported inconsistently across browsers, and even across versions of a single browser. The .attr() method reduces such inconsistencies.""
    – Ram
    Apr 14, 2012 at 20:53
0

I just figured out why. I missed a space. I even copied the mistake here into the original post!

$('#edit-credentials').click(function() { 
    $('#credentials :input').prop("disabled", !$('#credentials:input').prop("disabled")) 
});

The space added in the #creditials :input.

$('#edit-credentials').click(function() { 
    $('#credentials :input').prop("disabled", !$('#credentials :input').prop("disabled")) 
});

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.