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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions src/main/scala/org/scalajs/dom/raw/lib.scala
Original file line number Diff line number Diff line change
Expand Up @@ -804,15 +804,35 @@ abstract class Element
*/
def getAttribute(name: String): String = js.native

/**
* Returns a list of elements with the given tag name. The subtree underneath the
* specified element is searched, excluding the element itself. The returned list is
* live, meaning that it updates itself with the DOM tree automatically.
* Consequently, there is no need to call several times
* element.getElementsByTagName with the same element and arguments.
*
* 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.


/**
* Returns a list of elements with the given tag name belonging to the given namespace.
*
* MDN
*/
def getElementsByTagNameNS(namespaceURI: String,
localName: String): NodeList = js.native
localName: String): HTMLCollection = js.native

def getElementsByClassName(classNames: String): NodeList = js.native
/**
* Returns an array-like object of all child elements which have all of the
* given class names. When called on the document object, the complete document
* is searched, including the root node. You may also call getElementsByClassName()
* on any element; it will return only elements which are descendants of the
* specified root element with the given class names.
*
* MDN
*/
def getElementsByClassName(classNames: String): HTMLCollection = js.native

/**
* hasAttributeNS returns a boolean value indicating whether the current element
Expand Down Expand Up @@ -886,17 +906,6 @@ abstract class Element
*/
def getAttributeNode(name: String): Attr = js.native

/**
* Returns a list of elements with the given tag name. The subtree underneath the
* specified element is searched, excluding the element itself. The returned list is
* live, meaning that it updates itself with the DOM tree automatically.
* Consequently, there is no need to call several times
* element.getElementsByTagName with the same element and arguments.
*
* MDN
*/
def getElementsByTagName(name: String): NodeList = js.native

/**
* Returns a collection of rectangles that indicate the bounding rectangles for each
* box in a client.
Expand Down Expand Up @@ -2850,7 +2859,7 @@ abstract class Document
*
* MDN
*/
def getElementsByTagName(tagname: String): NodeList = js.native
def getElementsByTagName(name: String): HTMLCollection = js.native

/**
* Returns a list of elements with the given tag name belonging to the given namespace.
Expand All @@ -2859,7 +2868,7 @@ abstract class Document
* MDN
*/
def getElementsByTagNameNS(namespaceURI: String,
localName: String): NodeList = js.native
localName: String): HTMLCollection = js.native

/**
* Returns a set of elements which have all the given class names. When called on the
Expand All @@ -2869,7 +2878,7 @@ abstract class Document
*
* MDN
*/
def getElementsByClassName(classNames: String): NodeList = js.native
def getElementsByClassName(classNames: String): HTMLCollection = js.native

/**
* Returns the element from the document whose elementFromPoint method is being
Expand Down