HtmlElementCollection.Item[] Property

Definition

Gets an item from the collection.

Overloads

Item[Int32]

Gets an item from the collection by specifying its numerical index.

Item[String]

Gets an item from the collection by specifying its name.

Remarks

HtmlElementCollection objects are read-only. To add an element to an HTML document, use methods such as InsertAdjacentElement and AppendChild.

Item[Int32]

Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs

Gets an item from the collection by specifying its numerical index.

C#
public System.Windows.Forms.HtmlElement this[int index] { get; }
C#
public System.Windows.Forms.HtmlElement? this[int index] { get; }

Parameters

index
Int32

The position from which to retrieve an item from the collection.

Property Value

An item from the collection by specifying its numerical index.

Remarks

Elements in an HtmlElementCollection are not guaranteed to be in source code order. In other words, just because a DIV element is the first element inside of a BODY tag does not mean that the first element of the collection will be the DIV element.

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

Item[String]

Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs
Source:
HtmlElementCollection.cs

Gets an item from the collection by specifying its name.

C#
public System.Windows.Forms.HtmlElement this[string elementId] { get; }
C#
public System.Windows.Forms.HtmlElement? this[string elementId] { get; }

Parameters

elementId
String

The Name or Id attribute of the element.

Property Value

An HtmlElement, if the named element is found. Otherwise, null.

Examples

The following code example finds a FORM object using its name, and submits its data to the server programmatically. The code example requires that your application hosts a WebBrowser control named webBrowser1.

C#
private void SubmitForm(String formName)
{
    HtmlElementCollection elems = null;
    HtmlElement elem = null;

    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        elems = doc.All.GetElementsByName(formName);
        if (elems != null && elems.Count > 0)
        {
            elem = elems[0];
            if (elem.TagName.Equals("FORM"))
            {
                elem.InvokeMember("Submit");
            }
        }
    }
}

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9