I have been asked to identify all read only text boxes in an Asp.Net page and assign a particular style. I'm pretty sure I could iterate over all of the inputs to see if they were inputs that were text boxes with the readonly attribute but I just KNOW there's a one liner.
Any thoughts?
So use the same attribute "readonly" to find out whether textbox is readonly or not using jQuery. $(document). ready(function(){ $("#txtReadonly"). attr('readonly', true); var isReadonly = $("#txtReadonly").
How can you make a textbox readonly using JQuery? $('#TextBoxId'). attr('readonly', 'true'); 1.
Use jQuery methods to add the readonly attribute to the form input field. jQuery attr() Method: This method set/return attributes and values of the selected elements. If this method is used to return the attribute value, it returns the value of the first selected element.
Use the readOnly property to check if an element is read-only, e.g. if (element. readOnly) {} . The readOnly property returns true when the element is read-only, otherwise false is returned.
Is this what you're looking for?
$('input[type=text][readonly]')
http://jsfiddle.net/rZvnm/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With