System.Windows.Forms.HtmlElement.InnerHtml Property

Gets or sets the HTML markup underneath this element.

Syntax

public string InnerHtml { set; get; }

Value

Documentation for this section has not yet been entered.

Remarks

There are several ways to add new elements to an existing HTML page, such as the HtmlElement.AppendChild(HtmlElement) and HtmlElement.InsertAdjacentElement(HtmlElementInsertionOrientation, HtmlElement) methods. Using HtmlElement.InnerHtml is often the fastest way to add new content when you have to set many attributes or styles on your new elements.

HtmlElement.InnerHtml differs from HtmlElement.OuterHtml in that HtmlElement.InnerHtml will not include the HTML that represents the object you are calling. See HtmlElement.OuterHtml for more information about the difference between these two properties.

Setting HtmlElement.InnerHtml destroys any children previously appended to the element. If you retrieve an element from the DOM and then assign new HTML to its parents' HtmlElement.InnerHtml property, your reference to that element will be useless, and its behavior when it calls its properties and methods is undefined.

For some elements, setting HtmlElement.InnerHtml is not a valid operation. Some HTML tags have no closing tag, such as the IMG tag, and therefore cannot contain nested elements. Some tags, such as the SCRIPT tag, can only contain text content; setting HtmlElement.InnerHtml will result in an error. For both types of tags, the HtmlElement.CanHaveChildren property will return false. However, you also cannot set HtmlElement.InnerHtml on TABLE and TR elements, as assigning malformed HTML to these elements could corrupt the rendering of the document. Use HtmlElement.AppendChild(HtmlElement) or the insertRow and insertCell methods on the unmanaged IHTMLTable interface to add rows and cells to a TABLE.

If you need only to assign text to an element and not HTML markup, use the HtmlElement.InnerText property instead.

Assigning a value to HtmlElement.InnerHtml will destroy any text values previously assigned using HtmlElement.InnerText.

Requirements

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