Currently, my code looks like this:
var links = document.getElementsByTagName('a');
It's meant to collect all the links on the page, but we need to make some changes.
When I use console log to check links, I see an HTMLCollection with over 100 'a' elements. However, links.length returns 0.
I've attempted various methods to convert this HTMLCollection to an array, but none of them seem to be effective.
Array.from(links)
Array.prototype.slice.call(links)
[].forEach.call(links, function (el) {...});
HTMLCollection.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator];
HTMLCollection.prototype.forEach = Array.prototype.forEach;
Every one of these attempts results in an empty array.
Furthermore,
var links = document.querySelectorAll('a');
also gives me an empty NodeList.
I've reached a dead end. The original links variable definitely contains elements, so it's perplexing why none of these approaches are successful. In addition, utilizing jQuery is not an option for our project.