HtmlDocument.Body Property

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Gets the HtmlElement for the BODY tag.

Namespace:   System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)

public HtmlElement Body { get; }

Property Value

Type: System.Windows.Forms.HtmlElement

The HtmlElement object for the BODY tag.

An HTML document is split into two major sections:

  • HEAD, which contains the document's title, any document meta-data, and SCRIPT elements.

  • BODY, which contains all of the elements involved in the on-screen appearance of the document.

There is no equivalent Head property on HtmlDocument. To obtain the HEAD element, use GetElementsByTagName.

The following code example creates a new DIV element and appends it to the bottom of the document using the AppendChild method.

private void AppendText(String text)
{
    if (webBrowser1.Document != null)
    {
        HtmlDocument doc = webBrowser1.Document;
        HtmlElement textElem = doc.CreateElement("DIV");
        textElem.InnerText = text;
        doc.Body.AppendChild(textElem);
    }
}

.NET Framework
Available since 2.0
Return to top
Show: