Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: forEach is not a function in a HTMLCollection #989

Closed
ahuegle opened this issue Sep 28, 2021 · 2 comments
Closed

TypeError: forEach is not a function in a HTMLCollection #989

ahuegle opened this issue Sep 28, 2021 · 2 comments

Comments

@ahuegle
Copy link

ahuegle commented Sep 28, 2021

const all = document.querySelectorAll('*') console.log('all', all) all.forEach(it => console.log(it)); // works const divs = document.getElementsByTagName('p') console.log('divs', divs) divs.forEach(div => { console.log('div', div) // error });

second forEach gives an error although debug notes says the polyfills are included:

Added following core-js polyfills:
es.array.for-each { "ie":"11" }
web.dom-collections.for-each { "ie":"11" }

Happens with babel7, webpack or rollup.

@zloirock
Copy link
Owner

zloirock commented Sep 28, 2021

HTMLCollection haven't a .forEach method by the standard. In some recent core-js versions it was added because of a bug, but it was never documented. core-js adds .forEach only to DOMTokenList and NodeList from DOM collections.

@ahuegle
Copy link
Author

ahuegle commented Sep 28, 2021

Ok, thx, i see it in release notes 3.18.1.
We will use [...document.getElementsByTagName('p')].forEach()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants