How can i add "readonly" to a specific <input >
? .attr('readonly') does not work.
views:
5229answers:
4
+2
A:
.attr('readonly', 'readonly')
should do the trick. Your .attr('readonly')
only returns the value, it doesn't set one.
ceejayoz
2009-08-20 14:50:47
jQuery's attr() works on JavaScript properties, not HTML attributes, even though the names imply otherwise. attr('readonly') is actually operating on the DOM Level 1 HTML property readOnly, which is a boolean, so ‘true’ is more appropriate. However, the string 'readonly' is also a truthy value when automatically converted to a boolean, so the above still works.
bobince
2009-09-11 17:00:45
A:
For enabling readonly:
$("#descrip").attr("readonly","true");
For disabling readonly
$("#descrip").attr("readonly","");
Pradeep
2010-08-19 13:51:48