我需要更改div中的單詞顏色。它充滿了dinamically,有一個JavaScript函數讀取數據庫並寫入我的div的ID。 我試圖色字INFO(僅INFO),都沒有成功:如何將顏色更改爲div內的html字
$("div:contains('INFO')").each(function() {
$(this).html($(this).html().replace("INFO", "<span class='green'>INFO</span>"));
});
/* THis is only an example*/
document.getElementById('textLog').innerHTML ="Load[DB]: INFO";
.green {
\t color: green;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div class="menuLog">
\t \t <div class="log">
\t \t \t <h3 class="textStyle">Log</h3>
\t \t \t <div id="textLog" class="silverStyle" name="textLog" required></div><br>
\t \t </div>
\t </div>
這是否解決了您的問題? –
是的,我解決了它 –
這看起來幾乎與以前的答案相同,但如果它解決了你的問題,你應該選擇它 –