Here are 2 examples that works in IE and NN6. For both examples it's necessary that all the numbers are enclosed with HTML-tags :
1st example, if the number could be in any HTML tag:
<HTML>
<HEAD>
<script language="javascript">
[ignore]
function changeColor()
{
var di = document.body.all;
for (i=0; i<di.length; i++)
{
if (di.innerHTML < 0)
{
di.style.color = "red";
}
else if (di.innerHTML >= 0)
{
di.style.color = "green";
}
}
}
</script>
[/ignore]
</HEAD>
<BODY onload="changeColor()">
<br>
<table border=1>
<tr>
<td>1
</td>
<td>-1
</td>
<td>3
</td>
</tr>
<tr>
<td>0
</td>
<td>-4
</td>
<td>6
</td>
</tr>
<tr>
<td>-12
</td>
<td>text
</td>
<td>9
</td>
</tr>
</table>
<br>
<p>This is a text with a positive number <span>25</span> and a negative number <span>-34.56</span> and a zero <span>0</span></P>
<br>
<div>3000</div>
<div>-3000</div>
<span>-23 pages</span> (The text "23 pages" stays black!)<br>
<span>-23</span> pages
<div>-3</div>
<div>-0.0001</div>
<br>
</BODY>
</HTML>
This example loops trough ALL the HTML-tags, so also the <br>, <table>, <tr>, <p> etc. who are containing other text or nested HTML-tags. If you have a large file the performance could got worse.
2nd example, if the number only are in a specific HTML tag:
[ignore]
<script language="javascript">
function changeColor()
{
for (i=0; i<di.tags('TD').length; i++)
{
if (di.tags('TD').innerHTML < 0)
{
di.tags('TD').style.color = "yellow"
}
else if (di.tags('TD').innerHTML >= 0)
{
di.tags('TD').style.color = "orange"
}
}
for (i=0; i<di.tags('DIV').length; i++)
{
if (di.tags('DIV').innerHTML < 0)
{
di.tags('DIV').style.color = "blue"
}
else if (di.tags('DIV').innerHTML >= 0)
{
di.tags('DIV').style.color = "#FF40FF"
}
}
for (i=0; i<di.tags('SPAN').length; i++)
{
if (di.tags('SPAN').innerHTML < 0)
{
di.tags('SPAN').style.color = "red"
}
else if (di.tags('SPAN').innerHTML >= 0)
{
di.tags('SPAN').style.color = "green"
}
}
}
</script>
[/ignore]
Hope this helps,
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.