question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

getElementsByTagName should return HTMLCollection

See original GitHub issue

TypeScript 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:open
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
HolgerJeromincommented, Nov 2, 2018

IMO the original request and both issues from @JacksonKearl are solved (at least in TS3.1).

0reactions
JacksonKearlcommented, Aug 17, 2018

Also HTMLCollection is typed as having a forEach method but it does not. https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found