zenon905 Posted February 16, 2008 Share Posted February 16, 2008 document.write("aaa")How do I change the colour of aaa using javascript? Link to comment Share on other sites More sharing options...
Ingolme Posted February 16, 2008 Share Posted February 16, 2008 document.write("<span style=\"color: red\">aaa</span>"); Link to comment Share on other sites More sharing options...
zenon905 Posted February 16, 2008 Author Share Posted February 16, 2008 How do I change the colour of a document.write text after a few seconds with setInterval or setTimeout? Link to comment Share on other sites More sharing options...
Ingolme Posted February 16, 2008 Share Posted February 16, 2008 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 More sharing options...
zenon905 Posted February 17, 2008 Author Share Posted February 17, 2008 How do I make a word change between 2 colours in an interval with the least confusing code possible? Link to comment Share on other sites More sharing options...
Synook Posted February 17, 2008 Share Posted February 17, 2008 <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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.