hey all,
i'm very new to DOM and javascripting. I found a tutorial somewhere and i was playing around with it but it got stuck on getting the value of a node that i just append at the end. It returns me an empty string when i try to get the node value. I've looked around but no luck making my code work. Any help will be appreciated, thanking in advance! Please see the code below
i'm very new to DOM and javascripting. I found a tutorial somewhere and i was playing around with it but it got stuck on getting the value of a node that i just append at the end. It returns me an empty string when i try to get the node value. I've looked around but no luck making my code work. Any help will be appreciated, thanking in advance! Please see the code below
Code:
<html>
<head><title>JavaScript</title>
</head>
<body>
<div style='position:absolute; width:150px; height:100px;overflow:auto' id = 'scroll_text'> </div>
<script language='javascript'>
function move_up() {
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)
}
alert(obj.firstChild.nodeType)
var ochildNodes = obj.childNodes
var len = ochildNodes.length
alert(len)
alert(obj.firstChild.nodeValue) // the following line returns an empty string
//]ultimately i would like to do this
//obj.firstChild.style.backgroundColor="#0000FF"
}
move_up()
</script>
</body>
</html>
Comment