Jump to content

Change text colour


zenon905

Recommended Posts

If you call document.write() after the page loads you're going to clear all the contents of the page, so it wouldn't work.What I recommend is to have an element to hold the text in and modify the text there:----The node to hold the text:<span id="text"></span>----An exemplary function:function doSomething() {document.getElementById("text").firstChild.nodeValue = "some text";document.getElementById("text").style.color = "red";}

Link to comment
Share on other sites

<script type="text/javascript">	function changecolor(item) {		var text = document.getElementById(item);		if (text.style.color == "#FF0000") text.style.color = "#0000FF";		else text.style.color = "#FF0000";	}	window.onload = function() { setInterval("changecolor(\"text\")", 1000); }</script><div id="text">This text will change color red/blue in one second intevals.</div>

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...