[英]Javascript: how to change contenteditable div placeholder color
I want to us javascript to change the placeholder color of the contenteditable div when an event triggered. 我想让我们的JavaScript在事件触发时更改contenteditable div的占位符颜色。 But what is Javascript/Jquery selector for this big guy?
但是这个大个子的Javascript / Jquery选择器是什么?
I tried: 我试过了:
$("#topic_content_input[data-placeholder]:not([data-div-placeholder-content]):before").css({"color":"blue"});
Demo 演示
<div id="topic_content_input" contenteditable="true" data-placeholder="I want to change my color on click " ></div>
<style>
#topic_content_input[data-placeholder]:not([data-div-placeholder-content]):before {
content: attr(data-placeholder);
float: left;
margin-left: 2px;
color: rgba(134,134,134,0.6);
}
</style>
You can do like following way using JQuery. 您可以使用JQuery按照以下方式进行操作。 Use
addClass
. 使用
addClass
。
jQuery(function($){ $("#topic_content_input").click(function(){ $(this).addClass('placeholder'); }); });
.topic_content_input[data-placeholder]:not([data-div-placeholder-content]):before { content: attr(data-placeholder); float: left; margin-left: 2px; color: rgba(134,134,134,0.6); } .placeholder[data-placeholder]:not([data-div-placeholder-content]):before { color: rgba(0,0,255,1); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div id="topic_content_input" class="topic_content_input" contenteditable="true" data-placeholder="I want to change my color on click " ></div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.