var collection = document.getElementsByClassName("collection"); var element = document.createElement("p"); element.className = "collection"; document.body.appendChild(element); // Checking the length console.log(collection.length); > 1 console.log(collection[0]); > <p class="collection"></p> The new element found its way into our collection array without having to re-fetch it from the DOM.