PDA

View Full Version : set background colour of a text


msalman
06-27-2007, 06:53 PM
hey all,

Could someone please tell me how can i change the background colour of a text in any container which is added using javascript. For example if i've the following code

<html>
<head><title>JavaScript</title>
</head>
<body>

<div id = 'text'> </div>

<script language='javascript'>

function addText() {

var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"

var obj = document.getElementById("scroll_text")

for (i=0;i<mycars.length;i++)
{

var mytext=document.createTextNode(mycars[i] + " ")
obj.appendChild(mytext)

}

var ochildNodes = obj.childNodes

var len = ochildNodes.length

// i would like this line to work but it doesn't
ochildNodes[0].style.backgroundColor="#0000FF"

}

addText()

</script>

</body>

</html>

Is it possible to change the background colour of specified childnode? Thanking in avdance!