I've been learning about javascript and childnodes. For an exercise, we have to switch the text of listitems to uppercase through the use of a parent node.
Right now, it seems to add the values in javascript to the list, instead of changing them. It only needs to change the original text value.
I think I'm pretty close but I get some odd results (this doesn't happen when I do it without childnodes). It's probably something minor, but I still appreciate anyone giving it a look!
javascript
addEventListener("load",init,false);
function init(){
let span = document.getElementsByClassName("aantal");
span[0].innerHTML = "3";
let node = document.getElementsByClassName("list")[0].parentNode;
node.firstChild.nodeValue = "ROOD";
node.childNodes[1].nodeValue = "GROEN";
node.childNodes[2].nodeValue = "BLAUW";
}
html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Slides Opdracht04</title>
<link href="style/stijl.css" rel="stylesheet" />
<script src="js/demo4.js"></script>
</head>
<body>
<p>Kleuren</p>
<ul>
<li class="list">Rood</li>
<li class="list">Groen</li>
<li class="list">Blauw</li>
</ul>
<p>De lijst bevat <span class="aantal"></span> kleuren</p>
</body>
</html>