The HTMLCollection Object
An HTMLCollection object is an array-like list of HTML elements.
An HTMLCollection
which is a live, ordered collection of the DOM elements which are children of node
. You can access the individual child nodes in the collection by using either the item()
method on the collection, or by using JavaScript array-style notation.
Methods like the getElementsByTagName() or getElementsByClassName returns an HTMLCollection.
Example:
Nodelist gives more option , can use document.querySelectorAll instead of documentByClassName
Nodelist:
document.querySelectorAll('a')
NodeList(269) [a#logo.yt-simple-endpoint.style-scope.ytd-topbar-logo-renderer, a.yt-simple-endpoint.style-scope.ytd-button-renderer, a.yt-simple-endpoint.style-scope.ytd-topbar-menu-button-renderer,
Sample differences of HTML collection and nodelist:
document.getElementsByClassName('title-and-badge')
HTMLCollection(20)
[h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer]
document.querySelectorAll('.title-and-badge')
NodeList(20)
[h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer, h3.title-and-badge.style-scope.ytd-video-renderer]
No comments:
Post a Comment