Export (0) Print
Expand All

HtmlElement.OuterHtml Property

Gets or sets the current element's HTML code.

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

public string OuterHtml { get; set; }

Property Value

Type: System.String
The HTML code for the current element and its children.

Whereas InnerHtml will return all HTML contained in the current element excluding the current element's surrounding tags, OuterHtml includes the current element's tag as well as the HTML that tag contains, for example:

<HTML>

<BODY>

<DIV id="div1">

Hello

<DIV id="div2">

World

<DIV id="div3">

How are you?

</DIV>

</DIV>

</DIV>

</BODY>

</HTML>

In this example, calling OuterHtml on div2 will return:

<DIV id="div2">

World

<DIV id="div3">

How are you?

</DIV>

</DIV>

Calling InnerHtml will return:

World

<DIV id="div3">

How are you?

</DIV>

If you assign a new value to OuterHtml, the current element reference will become invalid; it will not reflect the name, properties and child content of the HTML you have just assigned.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft