Skip to content

Return HTMLCollection in getElementsBy*() #315

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

Merged
merged 1 commit into from
Mar 5, 2018

Conversation

tindzk
Copy link
Contributor

@tindzk tindzk commented Feb 26, 2018

At the moment, all getElementsBy* functions return a NodeList, but the items are guaranteed to be Elements. Therefore, to access an item as an Element, a cast is required.

Furthermore, I would propose to remove the function getElementsByName() which does not appear in the DOM interfaces and seems to have been superseded by getElementsByTagName(). If you agree, I will add a separate commit for it to this pull request.

See also:

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't there something about SVG DOM things that precisely aren't Elements but Nodes? Or am I confused about something else?

*
* MDN
*/
def getElementsByTagName(name: String): HTMLCollection = js.native
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this moved from its previous location? It creates a bigger diff than necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved it for more consistency with Document and the DOM specification, which both declare getElementsByTagName first and getElementsByTagNameNS afterwards. When I originally saw the file, I was under the impression that getElementsByTagName was missing and added it. This confusion could have been avoided if it was placed before getElementsByTagNameNS.

@tindzk
Copy link
Contributor Author

tindzk commented Mar 5, 2018

If you have svg nodes in mind, getElementsByTagName("svg") would return a node list of Elements (which is exactly what an HTMLCollection is). The Typescript's bindings are actually more expressive and return NodeListOf<SVGSVGElement>. In Scala 2.13, we could implement it the same way with literal types.

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK thanks for the clarifications.

@sjrd sjrd merged commit a5b9ae4 into scala-js:master Mar 5, 2018
@tindzk tindzk deleted the getelementsby branch March 5, 2018 21:35
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

Successfully merging this pull request may close these issues.

2 participants