admin管理员组文章数量:1326700
I know how to do this in JavaScript/jQuery but I am wondering if there's a way to do this in CSS?
I know we can target the placeholder containing a string using:
textarea[placeholder*="WORK"]{
background: purple;
}
Is there something similar for the value?
I tried textarea[value*="MY_STRING"]
but that didn't work probably because the value of the textarea is not an attribute unlike input
.
I know how to do this in JavaScript/jQuery but I am wondering if there's a way to do this in CSS?
I know we can target the placeholder containing a string using:
textarea[placeholder*="WORK"]{
background: purple;
}
Is there something similar for the value?
I tried textarea[value*="MY_STRING"]
but that didn't work probably because the value of the textarea is not an attribute unlike input
.
3 Answers
Reset to default 5No, as textarea currently only supports the following attributes:
autocapitalize
autoplete
autocorrect
autofocus
cols
form
maxlength
minlength
placeholder
readonly
required
rows
spellcheck
wrap
https://developer.mozilla/en-US/docs/Web/HTML/Element/textarea#attributes
i.e nothing based off what the user does
I havent got anything. But if you really want to use the value in the textarea you will have to duplicate the info perhaps by adding a data-info attribute and making the text similar to the value. And then use the data attribute to select the specific textarea. This is not a good way to do it but just thought it might help
<textarea data-info="My String">My String</textarea>
css might be like this
textarea[data-info="My String"]{ ....}
Again this is not the best way to do it.
You could use the <input>
element for this by giving it a pattern and making it required, then using the CSS :valid
pseudo-class. This does not work for <textarea>
because it does not support the pattern attribute.
input:valid{
background-color: purple;
}
<input type="text" pattern="^.*MY_STRING.*$" required/>
本文标签: javascriptIs it possible to use CSS selector for textarea valueStack Overflow
版权声明:本文标题:javascript - Is it possible to use CSS selector for textarea value? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742199031a2431613.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论