Edit

Share via


HtmlElement.AppendChild(HtmlElement) Method

Definition

Adds an element to another element's subtree.

public:
 System::Windows::Forms::HtmlElement ^ AppendChild(System::Windows::Forms::HtmlElement ^ newElement);
public System.Windows.Forms.HtmlElement AppendChild (System.Windows.Forms.HtmlElement newElement);
public System.Windows.Forms.HtmlElement? AppendChild (System.Windows.Forms.HtmlElement newElement);
member this.AppendChild : System.Windows.Forms.HtmlElement -> System.Windows.Forms.HtmlElement
Public Function AppendChild (newElement As HtmlElement) As HtmlElement

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.

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);
    }
}
Private Sub AddLinkToPage(ByVal url As String)
    If (WebBrowser1.Document IsNot Nothing) Then
        With WebBrowser1.Document
            Dim Elem As HtmlElement = .CreateElement("A")
            Elem.SetAttribute("HREF", url)
            Elem.InnerText = "Visit our web site for more details."

            .Body.AppendChild(Elem)
        End With
    End If
End Sub

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

See also