Filter a JavaScript array for HTML element type
To accomplish this task you will first need to convert the HTMLCollection into an Array it is not already.
From there you can call the .filter
function on the array and check to see if the nodeName
property of each element in the collection matches the condition you are expecting.
In practice that looks like the below example where the last line in the code example filters for and returns all elements in the collection that are <div>
.
parent = document.querySelectorAll(".blog")[0]
collection = Array.from(parent.children)
collection.filter(node => node.nodeName == "DIV")