I want to loop through a collection of HTML elements in a iframe and figure out the order in which a set of elements appear on screen, and then create a new list off the back of it.
I get the iframe div at const tempPageStructure = builderShowcase.frameElement.contentDocument["all"];
.
At the moment, I can't figure out, how to retrieve the element tag name as seen above, running the script below returns null at console.log(tempPageStructure[i].name);
.
const activeComponents = ['app-builder-navbar', 'app-builder-hero', 'app-builder-placeholder'];
const builderShowcase = $(builderShowcaseId).get(0).contentWindow;
function getPageStructure() {
const tempPageStructure = builderShowcase.frameElement.contentDocument["all"];
let pageStructure = [];
for(let i = 0; i < tempPageStructure.length; i++) {
console.log(tempPageStructure[i].name);
for(let j = 0; j < activeComponents.length; j++) {
if(tempPageStructure[i].name === activeComponents[j]) {
pageStructure.push(tempPageStructure[i])
}
}
}
console.log(tempPageStructure);
console.log(pageStructure);
return pageStructure;
}