1

I am trying to do it like this which has worked for me before but is not working for me now.

$("input").attr('disabled','disabled');

Can anyone tel me why it is not working while it has worked for me in previous projects.

2
  • This is actually a lot simpler with vanilla JavaScript. element.disabled = true Commented Feb 22, 2016 at 4:58
  • 6
    Possible duplicate of Disable/enable an input with jQuery? Commented Feb 22, 2016 at 4:58

2 Answers 2

2

What you are doing is old style was applicable for Jquery 1.5 and below. For version 1.6 and above you need to write this

$("input").prop('disabled', true);

Hope it helps.

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

Comments

0

You must have upgraded to newer version of jQuery which is greater than 1.5. For jQuery greater than 1.5, attr will not work but need to use prop as shown below.

$("input").prop('disabled','disabled');

1 Comment

Set the property to true (or false), not to a string.

Your Answer

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