Class HTMLCollection
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The HTMLCollection interface represents a generic collection (array-like object similar to Functions/arguments) of elements (in document order) and offers methods and properties for selecting from the list.
[Value("HTMLCollection")]
public class HTMLCollection
- Inheritance
-
HTMLCollection
- Derived
- Inherited Members
Remarks
An HTMLCollection in the HTML DOM is live; it is automatically updated when the underlying document is changed. For this reason it is a good idea to make a copy (e.g., using Array/from) to iterate over if adding, moving, or removing nodes.
This interface is called HTMLCollection for historical reasons, because before the modern DOM, collections implementing this interface could only have HTML elements as their items.
This interface was an attempt to create an unmodifiable list and only continues to be supported to not break code that's already using it. Modern APIs represent list structures using types based on JavaScript arrays, thus making many array methods available, and at the same time imposing additional semantics on their usage (such as making their items read-only).
These historical reasons do not mean that you as a developer should avoid HTMLCollection. You don't create HTMLCollection objects yourself, but you get them from APIs such as GetElementsByClassName(string), and these APIs are not deprecated. However, be careful of the semantic differences from a real array.
Constructors
HTMLCollection()
public HTMLCollection()
Properties
Length
The HTMLCollection.length property returns the number of
items in a HTMLCollection.
[Value("length")]
public ulong Length { get; }
Property Value
- ulong
An integer value representing the number of items in a
HTMLCollection.