admin管理员组文章数量:1024354
I'm using message.innerText for string output in google extension.
var text="hello world";
message.innerText = text;
Question is how to make bg color and text color different? Thank you!
I'm using message.innerText for string output in google extension.
var text="hello world";
message.innerText = text;
Question is how to make bg color and text color different? Thank you!
Share Improve this question asked Aug 6, 2017 at 18:53 Jessica RayJessica Ray 652 silver badges5 bronze badges3 Answers
Reset to default 1You should review the style
property of DOM nodes. That said, you are looking for backgroundColor
and color
:
message.style.backgroundColor = 'some valid color value';
message.style.color = 'some valid color value';
Use this code:
var message = document.getElementById("#message");
var text = "hello world";
message.innerText = text;
message.style.backgroundColor = "#ff0000";
message.style.color = "#ffffff";
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#message {
width: 300px;
height: 300px;
background-color: coral;
color: white;
}
</style>
</head>
<body>
<button onclick="myFunction()">Change Style</button>
<br /><br />
<div id="message">
Hello
</div>
<script>
function myFunction() {
var message = document.getElementById("message");
var text = "hello world";
message.innerText = text;
message.style.backgroundColor = "#ff0000";
message.style.color = "#ffffff";
}
</script>
</body>
</html>
you can change the background color and text color by using the style properties of elements. see below snippet.
var text="hello world";
var message = document.getElementById('message');
message.innerText = text;
message.style.backgroundColor = "RED";;
message.style.color = "white";
<span id="message"></span>
I'm using message.innerText for string output in google extension.
var text="hello world";
message.innerText = text;
Question is how to make bg color and text color different? Thank you!
I'm using message.innerText for string output in google extension.
var text="hello world";
message.innerText = text;
Question is how to make bg color and text color different? Thank you!
Share Improve this question asked Aug 6, 2017 at 18:53 Jessica RayJessica Ray 652 silver badges5 bronze badges3 Answers
Reset to default 1You should review the style
property of DOM nodes. That said, you are looking for backgroundColor
and color
:
message.style.backgroundColor = 'some valid color value';
message.style.color = 'some valid color value';
Use this code:
var message = document.getElementById("#message");
var text = "hello world";
message.innerText = text;
message.style.backgroundColor = "#ff0000";
message.style.color = "#ffffff";
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#message {
width: 300px;
height: 300px;
background-color: coral;
color: white;
}
</style>
</head>
<body>
<button onclick="myFunction()">Change Style</button>
<br /><br />
<div id="message">
Hello
</div>
<script>
function myFunction() {
var message = document.getElementById("message");
var text = "hello world";
message.innerText = text;
message.style.backgroundColor = "#ff0000";
message.style.color = "#ffffff";
}
</script>
</body>
</html>
you can change the background color and text color by using the style properties of elements. see below snippet.
var text="hello world";
var message = document.getElementById('message');
message.innerText = text;
message.style.backgroundColor = "RED";;
message.style.color = "white";
<span id="message"></span>
本文标签: javascriptJS messageinnerText font color and bg colorStack Overflow
版权声明:本文标题:javascript - JS: message.innerText font color and bg color - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745496292a2153181.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论