[英]Change text color in the inner html code to red
document.getElementById("something").innerHTML = "My name is Jeremy Gordon and this is my Portfolio of my work in the QCC Software Engineering Micro Credential Boot Camp.";
我需要将innerHTML
的文本更改为红色。 如何使此字符串中的文本变为红色。
您可以使用 DOM 样式color
属性:
document.getElementById( "something" ). innerHTML = "My name is Jeremy Gordon and this is my Portfolio of my work in the QCC Software Engineering Micro Credential Boot Camp."; document.getElementById( "something" ).style.color="red";
<p id="something"></p>
这会有所帮助。
您可以在此处了解有关 setAttribute 方法的更多信息: https : //www.w3schools.com/jsref/met_element_setattribute.asp
<script>
document.getElementById("something").setAttribute("style", "color: red;");
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.