In the following code example there are 3 div elements, none have an ID but each one is able to be uniquely accessed by being returned into an array. I'm wondering how JavaScript is keeping track of them? Is the browser assigning each object a unique reference? Is this unique reference discoverable or an attribute somewhere? Or is all that handled internally?
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
div {
width: 150px;
height: 150px;
background-color: red;
margin: 10px;
}
</style>
</head>
<body>
<div></div>
<div></div>
<div></div>
<script type="text/javascript">
var divArray = document.getElementsByTagName("div");
for (var i=0; i<divArray.length; i++){
divArray[i].onclick = function(){
this.style.display = "none";
}
}
</script>
</body>
</html>