HtmlElement.AppendChild Method (HtmlElement)

 

Adds an element to another element's subtree.

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

Public Function AppendChild (
	newElement As HtmlElement
) As HtmlElement

Parameters

newElement
Type: System.Windows.Forms.HtmlElement

The HtmlElement to append to this location in the tree.

Return Value

Type: System.Windows.Forms.HtmlElement

The element after it has been added to the tree.

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.

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 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

.NET Framework
Available since 2.0
Return to top
Show: