diff --git a/cigaradvisor/blocks/imagecta/imagecta.js b/cigaradvisor/blocks/imagecta/imagecta.js index 1caad0ba..73d2655e 100644 --- a/cigaradvisor/blocks/imagecta/imagecta.js +++ b/cigaradvisor/blocks/imagecta/imagecta.js @@ -1,27 +1,27 @@ export default function decorate(block) { const anchor = document.createElement('a'); [...block.children].forEach((row) => { - var link; + let link; [...row.children].forEach((col) => { const pic = col.querySelector('picture'); if (pic) { anchor.append(pic); } - if (col.textContent.toLowerCase() !== "image" && col.textContent.toLowerCase() !== "link") { + if (col.textContent.toLowerCase() !== 'image' && col.textContent.toLowerCase() !== 'link') { link = col.textContent; } }); - anchor.setAttribute("href", link); - - const children = block.children; + anchor.setAttribute('href', link); + }); + block.append(anchor); + const children = block.children; - // Loop through the children and remove those that are not anchor tags - for (let i = children.length - 1; i >= 0; i--) { - if (children[i].tagName !== 'A') { - console.log(children[i].tagName); - block.removeChild(children[i]); - } + // Loop through the children and remove those that are not anchor tags + Array.from(children).forEach((child) => { + if (child.tagName !== 'A') { + console.log(child.tagName); + block.removeChild(child); } }); - block.append(anchor); + } \ No newline at end of file