Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to know what is the best way to add a style in the code below so that the readonly textboxs are coloured grey?
$("[class*=q" + i + "_mark]").val(t_marksHtml).attr('readonly', true);
disabled
Try
$("selector for textbox").addClass("read-only-state");
and apply css in .read-only-state class
.read-only-state{ color:#333; background:grey; }
Add a comment
This can be done in pure CSS:
textarea[readonly]{ color: grey; }
or (better yet) left to the browser.
Why don't you use pure CSS?
input[readonly] { background-color: grey }
DEMO: http://jsfiddle.net/DqjAC/
CSS
textarea[readonly] { background: #999; }
just use attribute selector
$("input:[readonly]").css({"background":"#666"});
But its better to do with CSS only as
input[readonly]{ background: #666; }
basically, use this for all html tags with readonly attribute.
$("[readonly]").css("background-color","#CCC");
only input tags
$("input:[readonly]").css("background-color","#CCC");
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
disabledinputs are greyed out by default