HtmlElement.AppendChild(HtmlElement) メソッド

定義

要素を別の要素のサブツリーに追加します。

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

パラメーター

newElement
HtmlElement

ツリーのこの位置に追加する HtmlElement

戻り値

ツリーに追加された後の要素。

次のコード例では、 メソッドを使用して新しいハイパーリンクを CreateElement 作成し、 要素で を使用して AppendChild ページの末尾に BODY 追加します。 この例では、アプリケーションに という名前WebBrowser1のコントロールがWebBrowser含まれている必要があります。

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

注釈

HTML ドキュメント オブジェクト モデル (DOM) を使用すると、HTML ファイルの実行時の内容をさまざまな方法で変更できます。 既存のドキュメントに新しい要素を追加したり、ページ上の要素を移動したりするには、 を使用 AppendChild します。

要素が既に親になっている場合、別の要素に要素を追加すると、その要素が前の親から自動的に削除されます。

実行時に を使用AppendChildしてドキュメントに加えた追加は、コントロールで メソッドWebBrowserShowSaveAsDialog呼び出しても保持されません。

適用対象

こちらもご覧ください