...

View Full Version : writing different font depending on comparision result inner.html value



alvaritoe
10-07-2012, 03:09 PM
Hello

I have got this result



document.getElementById('rent').innerHTML



which outputs a number alright. However, I d like to be a bit fancier and want to output it red if it is equal to 5 or smaller and green otherwise.

I know that you change color by document.write(fontcolor("red"))

but I dont know how to embed this last document.write etc into the one I have above

xelawho
10-07-2012, 03:37 PM
<div id="rent"><div>
<script>
var x=3;
document.getElementById('rent').style.color=(x>5)?"green":"red";
document.getElementById('rent').innerHTML=x;
</script>

Philip M
10-07-2012, 04:01 PM
I know that you change color by document.write(fontcolor("red"))


document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum