I assign the results of document.getElementsByClassName("red") to the array redElements. I then change one element from class .red to class .blue. I expected redElements to keep its original three values, but instead it now contains only the two elements that are still red. This is surprising. What's the reason for this? What should I look up to learn more about why this happens?
<!DOCTYPE html>
<html>
<head>
<style>
.red { color: red; }
.blue { color: blue; }
</style>
</head>
<body>
<span class="red">1</span>
<span class="red">2</span>
<span class="red">3</span>
<script>
var redElements = document.getElementsByClassName("red");
alert(redElements.length);
firstRedElement = redElements[0];
firstRedElement.className = "blue";
alert(redElements.length);
</script>
</body>
</html>