setAttribute and text
Is it possible to change the colour of a text with setAttribute? This piece of code does what I asked it to do, it prints the text
"<font color=\"08870e\">Condition true</font>"
However I want it to recognize that I'm adding "font" container.
This is the code.
if(condition) {
$("status").set开发者_如何学C("text", "<font color=\"08870e\">Condition true</font>");
}
else
{
$("status").set("text", "<font color=\"03i9ie\">Condition false</font>");
}
if(condition2)
{
$("status2").set("text", "Condition 2 is true");
}
else
{
$("status2").set("text", "Condition 2 is false");
By the way, it's in the function which is called every 15 seconds therefore other methods aren't preferred.
Update: $ = document.getElementById
You need somthing like this:
$("status").text("Condition is true").css("color", "green");
$("status").text("Condition is false").css("color", "red"); // or .css("color", "#ff0000");
instead of named colors like "red"
, you can use hex rgb values "#ff0000"
Update: If $ = document.getElementById
then here's a JS way:
$("status").innerText = "Condition is false"; // .textContent for anything other than IE < 9 and non IE browsers.
$("status").style.color = "#ff0000";
Apologies for assuming $ was part of jQuery. Removed the tag jQuery from here and edited the question.
精彩评论