Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLCollection
  4. length

HTMLCollection: length property

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheHTMLCollection.length property returns the number ofitems in aHTMLCollection.

Value

An integer value representing the number of items in aHTMLCollection.

Examples

Thelength property is often useful in DOM programming. It's often used totest the length of a list, to see if it exists at all. It's also commonly used as theiterator in afor loop, as in this example.

js
// All the elements with the class ".test" in the documentconst items = document.getElementsByClassName("test");// For each test item in the list,// append the entire element as a string of HTMLlet gross = "";for (let i = 0; i < items.length; i++) {  gross += items[i].innerHTML;}// gross is now all the HTML for the test elements

Specifications

Specification
DOM
# ref-for-dom-htmlcollection-length①

Browser compatibility

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp