HtmlElement.AppendChild(HtmlElement) Method

Definition

Adds an element to another element's subtree.

C#
public System.Windows.Forms.HtmlElement AppendChild(System.Windows.Forms.HtmlElement newElement);
C#
public System.Windows.Forms.HtmlElement? AppendChild(System.Windows.Forms.HtmlElement newElement);

Parameters

newElement
HtmlElement

The HtmlElement to append to this location in the tree.

Returns

The element after it has been added to the tree.

Examples

The following code example creates a new hyperlink using the CreateElement method and adds it to end of a page using AppendChild on the BODY element. The example requires that your application contains a WebBrowser control named WebBrowser1.

C#
private void AddUrlToTooltip(string url)
{
    if (webBrowser1.Document != null)
    {
        HtmlElement elem = webBrowser1.Document.CreateElement("A");
        elem.SetAttribute("HREF", url);
        elem.InnerText = "Visit our Web site for more details.";

        webBrowser1.Document.Body.AppendChild(elem);
    }
}

Remarks

The HTML Document Object Model (DOM) enables you to alter the run-time contents of an HTML file in a number of ways. Use AppendChild to add new elements to an existing document, or to move an element on the page.

If an element has already been parented, appending an element to another element will automatically remove that element from its previous parent.

Any additions made to a document at run-time using AppendChild will not be persisted when you call the ShowSaveAsDialog method on the WebBrowser control.

Applies to

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

See also