HtmlDocument::CreateElement Method (String^)

 

Creates a new HtmlElement of the specified HTML tag type.

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

public:
HtmlElement^ CreateElement(
	String^ elementTag
)

Parameters

elementTag
Type: System::String^

The name of the HTML element to create.

Return Value

Type: System.Windows.Forms::HtmlElement^

A new element of the specified tag type.

elementTag may be one of any of the supported HTML tags in Internet Explorer, except for FRAME or IFRAME.

CreateElement returns an element unattached to the current document tree. To add the element to the document, use either the InsertAdjacentElement or AppendChild methods.

This method will not affect the state of an existing document's source code when you use the WebBrowser control's View Source context menu command or the DocumentText and DocumentStream properties of the WebBrowser control.

When you create new elements with CreateElement, you will not be able to set certain properties, such as Name. In cases where you need to set the Name attribute, assign them as HTML to the InnerHtml property of another object in the document.

The following code example uses data from the Northwind database to create an HTML table using CreateElement. The AppendChild method is also used, first to add cells (TD elements) to rows (TR elements), then to add rows to the table, and finally to append the table to the end of the current document. The code example requires that your application has a WebBrowser control called WebBrowser1.

No code example is currently available or this language may not be supported.

.NET Framework
Available since 2.0
Return to top
Show: