0

How can I set the disabled and readonly properties of a <select> and <input> element with jQuery? Also can someone please explain the difference. It seems to me that both properties would do the same thing.

Samantha J T Star
  • 28,982
  • 82
  • 233
  • 406
  • 2
    http://stackoverflow.com/questions/7730695/whats-the-difference-between-disabled-disabled-and-readonly-readonly-for-te – Tim M. Aug 21 '12 at 04:06

1 Answers1

1
$('input,select').attr('disabled','disabled')
$('input').attr('readonly','readonly')

likewise…

$('input,select').removeAttr('disabled')
$('input').removeAttr('readonly')

EDIT: You might want to read about the difference between .prop() and .attr(). Although relatively old here's an official documentation covering it.

inhan
  • 7,244
  • 2
  • 22
  • 35