admin管理员组文章数量:1404927
Is it possible to get current color value of an input
placeholder text?
Usually I'd use getComputedStyle
to get current element style values, but it does not return the placeholder value.
Any workarounds for this apart from parsing the css text and getting the value using regex?
Thanks.
Is it possible to get current color value of an input
placeholder text?
Usually I'd use getComputedStyle
to get current element style values, but it does not return the placeholder value.
Any workarounds for this apart from parsing the css text and getting the value using regex?
Thanks.
Share Improve this question edited May 24, 2016 at 10:13 Jakub Matczak 15.7k5 gold badges51 silver badges67 bronze badges asked May 24, 2016 at 9:58 SgoldySgoldy 7964 silver badges15 bronze badges3 Answers
Reset to default 4the second parameter of getComputedStyle
is pseudoElt selector
so to get placeholder color of your input element:
var styles = window.getComputedStyle(inputEl, ':placeholder');
console.log(styles.getPropertyValue('color'));
It's
window.getComputedStyle(inputEl, '::placeholder').getPropertyValue("color");
// note the DOUBLE colon here ----^^
Works in both Chrome and Firefox
Usually placeholder we have to use a class name and then change the placeholder color
input.text-filed::-webkit-input-placeholder {
color: red;
}
So u know the class which is have the color
本文标签: cssGet placeholder color using JavascriptStack Overflow
版权声明:本文标题:css - Get ::placeholder color using Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744875552a2629893.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论