I’m just starting to learn JavaScript and DOM and I have a newbie question for you.
I’m having some problems with the nodeValue method, so I would like if someone could explain me what am I doing wrong here.
Here’s my code:
[CODE]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Untitled Document</title>
<script type=”text/javascript” src=”test.js”></script>
<style>
@import “stil.css”;
</style>
</head>
<body>
<ul id=”glavno” >
ITEMS
<li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
<script type=”text/javascript”>
l1=document.getElementById(“glavno”);
for (i=0;i<l1.childNodes.length;i++){
if(l1.childNodes[i].nodeName==”#text”){
document.write(l1.childNodes[i].nodeValue);
}
}
</script>
</body>
</html>
If you test the code you’ll see that document.write writes only “ITEMS”, and I’m wondering why is that so? Shouldn’t it write values between <li> tags since li elements are child elements/nodes?
I just want to show the content that is between <li> tags, so should I use innerHTML instead?