Jump to content

Change text colour


zenon905
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...