From 0f9ec01005afb649115eedff2c5b8a14c3e00560 Mon Sep 17 00:00:00 2001 From: Charles Iliya Krempeaux Date: Wed, 15 Nov 2023 11:30:50 -0800 Subject: [PATCH] initial commits --- ziba.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/ziba.js b/ziba.js index 1af50f5..9994f23 100644 --- a/ziba.js +++ b/ziba.js @@ -41,7 +41,15 @@ function transform_link(rootElement) { return } - [].forEach.call(elements, function(element) { + // Because we are doing a replaceWith() on the HTMLCollection, + // we need to iterate through it backwards, because the HTMLCollection + // will change size and what is in it each time we do that. + // + //@TODO: Is there a better way of dealing with this? + for (let i = length-1; i >= 0; i--) { + + const element = elements[i] + const anchor = document.createElement("a") anchor.innerHTML = element.innerHTML @@ -56,5 +64,5 @@ function transform_link(rootElement) { anchor.setAttribute("href", href) element.replaceWith(anchor) - }) + } }