getElementsByTagName should return HTMLCollection
See original GitHub issueTypeScript Version: 2.1.4
Code
const nodeList = document.getElementsByTagName("p");
nodeList instanceof NodeList; // returns false, although lib.d.ts says it returns NodeList
Example: http://codepen.io/DaSch/pen/OWPvZZ
Expected behavior: document.getElementsByTagName(“*”) is defined to return HTMLCollection
Actual behavior: document.getElementsByTagName(“*”) is defined to return NodeList
Spec: https://dom.spec.whatwg.org/#dom-element-getelementsbytagname https://developer.mozilla.org/en-US/docs/Web/API/Element/getElementsByTagName
Issue Analytics
- State:
- Created 7 years ago
- Reactions:2
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Why is getElementsByTagName() returning an html ...
I have attempted getting IDs, classes, and other methods of reference DOM elements, they all work. But classes has the same issue here,...
Read more >Element.getElementsByTagName() - Web APIs | MDN
The Element.getElementsByTagName() method returns a live HTMLCollection of elements with the given tag name.
Read more >HTML DOM Document getElementsByTagName() Method
The getElementsByTagName() method returns an HTMLCollection. The getElementsByTagName() property is read-only.
Read more >286685 - document.getElementsByTagName should return ...
Yes, however the object returned by getElementsByTagName is a NodeList, which is observable. ... Yes, but given that both Gecko and Trident return...
Read more >JavaScript getElementsByTagName
The getElementsByTagName() method accepts a tag name and returns a live HTMLCollection of elements with the matching tag name in the order which...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
IMO the original request and both issues from @JacksonKearl are solved (at least in TS3.1).
Also
HTMLCollection
is typed as having aforEach
method but it does not. https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection