[英]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.