# HtmlElement

An owned element with ordered, namespace-aware attributes.

Class 

`OfficeIMO.Html.Dom`

**Namespace**

`OfficeIMO.Html.Dom`

**Assembly**

`OfficeIMO.Html.Core`

**Source revision**

`ba882f6b0d07` with working tree changes

**Source**

[HtmlElement.cs:53](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L53)

**Base**

`HtmlNode`

**Modifiers**

sealed

An owned element with ordered, namespace-aware attributes.

## Inheritance

- [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)
- HtmlElement

## Usage

Explore 31 API references to this type

This type appears in these public API surfaces even when no hand-authored example is attached directly to the page.

### Returned or exposed by 26

- Method [HtmlDocument.CreateElement](/api/html-core/officeimo-html-dom-htmldocument/#method-createelement-string-string-string)
- Method [HtmlDocument.QuerySelector](/api/html-core/officeimo-html-dom-htmldocument/#method-queryselector-string)
- Method [HtmlDocument.QuerySelectorAll](/api/html-core/officeimo-html-dom-htmldocument/#method-queryselectorall-string)
- Property [HtmlDocument.Body](/api/html-core/officeimo-html-dom-htmldocument/#property-body)
- Property [HtmlDocument.Children](/api/html-core/officeimo-html-dom-htmldocument/#property-children)
- Property [HtmlDocument.DocumentElement](/api/html-core/officeimo-html-dom-htmldocument/#property-documentelement)
- Property [HtmlDocument.Head](/api/html-core/officeimo-html-dom-htmldocument/#property-head)
- Property [HtmlDocument.ParentElement](/api/html-core/officeimo-html-dom-htmldocument/#property-parentelement)
- Method [HtmlDocumentFragment.QuerySelector](/api/html-core/officeimo-html-dom-htmldocumentfragment/#method-queryselector-string)
- Method [HtmlDocumentFragment.QuerySelectorAll](/api/html-core/officeimo-html-dom-htmldocumentfragment/#method-queryselectorall-string)
- Property [HtmlDocumentFragment.Children](/api/html-core/officeimo-html-dom-htmldocumentfragment/#property-children)
- Property [HtmlDocumentFragment.ParentElement](/api/html-core/officeimo-html-dom-htmldocumentfragment/#property-parentelement)
- Method [HtmlDocumentType.QuerySelector](/api/html-core/officeimo-html-dom-htmldocumenttype/#method-queryselector-string)
- Method [HtmlDocumentType.QuerySelectorAll](/api/html-core/officeimo-html-dom-htmldocumenttype/#method-queryselectorall-string)
- Property [HtmlDocumentType.Children](/api/html-core/officeimo-html-dom-htmldocumenttype/#property-children)
- Property [HtmlDocumentType.ParentElement](/api/html-core/officeimo-html-dom-htmldocumenttype/#property-parentelement)
- Method [HtmlElement.Closest](/api/html-core/officeimo-html-dom-htmlelement/#method-closest-string)
- Method [HtmlElement.QuerySelector](/api/html-core/officeimo-html-dom-htmlelement/#method-queryselector-string)
- Method [HtmlElement.QuerySelectorAll](/api/html-core/officeimo-html-dom-htmlelement/#method-queryselectorall-string)
- Property [HtmlElement.Children](/api/html-core/officeimo-html-dom-htmlelement/#property-children)
- Property [HtmlElement.ParentElement](/api/html-core/officeimo-html-dom-htmlelement/#property-parentelement)
- Method [HtmlNode.QuerySelector](/api/html-core/officeimo-html-dom-htmlnode/#method-queryselector-string)
- Method [HtmlNode.QuerySelectorAll](/api/html-core/officeimo-html-dom-htmlnode/#method-queryselectorall-string)
- Property [HtmlNode.Children](/api/html-core/officeimo-html-dom-htmlnode/#property-children)
- Property [HtmlNode.ParentElement](/api/html-core/officeimo-html-dom-htmlnode/#property-parentelement)
- Method [IHtmlDomServices.QuerySelectorAll](/api/html-core/officeimo-html-dom-ihtmldomservices/#method-queryselectorall-officeimo-html-dom-htmlnode-string)

### Accepted by parameters 5

- Method [HtmlCssSelector.Matches](/api/html-core/officeimo-html-css-htmlcssselector/#method-matches-officeimo-html-dom-htmlelement) parameter `element`
- Method [HtmlCssSelectorList.Matches](/api/html-core/officeimo-html-css-htmlcssselectorlist/#method-matches-officeimo-html-dom-htmlelement) parameter `element`
- Method [HtmlDocument.GetOrCreateTemplateContent](/api/html-core/officeimo-html-dom-htmldocument/#method-getorcreatetemplatecontent-officeimo-html-dom-htmlelement) parameter `template`
- Method [IHtmlDomServices.Matches](/api/html-core/officeimo-html-dom-ihtmldomservices/#method-matches-officeimo-html-dom-htmlelement-string) parameter `element`
- Method [IHtmlParserProvider.ParseFragment](/api/html-core/officeimo-html-dom-ihtmlparserprovider/#method-parsefragment-string-officeimo-html-dom-htmlelement-officeimo-html-dom-htmlparseoptions-threading-cancellationtoken) parameter `contextElement`

Filter members 

Show inherited

## Methods

`public HtmlElement? Closest(string selector)` [#](#method-closest-string)

[HtmlElement.cs:88](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L88)

Finds this element or its nearest ancestor matching a selector.

Parameters

**selector string required**

Returns

`HtmlElement?`

GetAttribute 2 overloads

`public string? GetAttribute(string name)` [#](#method-getattribute-string)

[HtmlElement.cs:53](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L53)

Reads the first attribute with this qualified name, regardless of namespace.

Parameters

**name string required**

Returns

`string?`

`public string? GetAttribute(string namespaceUri, string localName)` [#](#method-getattribute-string-string)

[HtmlElement.cs:57](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L57)

Reads an attribute by namespace URI and local name.

Parameters

**namespaceUri string required**

**localName string required**

Returns

`string?`

`public bool HasAttribute(string name)` [#](#method-hasattribute-string)

[HtmlElement.cs:55](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L55)

Checks whether a qualified attribute is present.

Parameters

**name string required**

Returns

`bool`

`public bool Matches(string selector)` [#](#method-matches-string)

[HtmlElement.cs:85](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L85)

Tests this element against a CSS selector.

Parameters

**selector string required**

Returns

`bool`

RemoveAttribute 2 overloads

`public void RemoveAttribute(string name)` [#](#method-removeattribute-string)

[HtmlElement.cs:75](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L75)

Removes the first attribute with this qualified name, regardless of namespace.

Parameters

**name string required**

`public void RemoveAttribute(string namespaceUri, string localName)` [#](#method-removeattribute-string-string)

[HtmlElement.cs:81](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L81)

Removes an attribute by namespace URI and local name.

Parameters

**namespaceUri string required**

**localName string required**

SetAttribute 2 overloads

`public void SetAttribute(string name, string value, string? namespaceUri = null)` [#](#method-setattribute-string-string-string)

[HtmlElement.cs:60](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L60)

Adds or replaces an attribute in the supplied namespace; omitting the namespace selects the empty namespace.

Parameters

**name string required**

**value string required**

**namespaceUri string? = null optional**

`public void SetAttribute(HtmlAttribute replacement)` [#](#method-setattribute-officeimo-html-dom-htmlattribute)

[HtmlElement.cs:67](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L67)

Adds or replaces an exact attribute by namespace and local name, preserving its qualified name and case.

Parameters

**replacement OfficeIMO.Html.Dom.HtmlAttribute required**

## Inherited Methods

`public HtmlNode AppendChild(HtmlNode child)` [#](#method-appendchild-htmlnode)

[HtmlNode.cs:74](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L74)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**child HtmlNode required**

Returns

`HtmlNode`

`public IEnumerable<HtmlNode> Descendants()` [#](#method-descendants)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Returns

`IEnumerable<HtmlNode>`

`public virtual bool Equals(object? obj)` [#](#method-equals-object)

Inherited from object

Parameters

**obj object? required**

Returns

`bool`

`public virtual int GetHashCode()` [#](#method-gethashcode)

Inherited from object

Returns

`int`

`public Type GetType()` [#](#method-gettype)

Inherited from object

Returns

`Type`

`public HtmlElement? QuerySelector(string selector)` [#](#method-queryselector-string)

[HtmlNode.cs:122](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L122)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**selector string required**

Returns

`HtmlElement?`

`public IReadOnlyList<HtmlElement> QuerySelectorAll(string selector)` [#](#method-queryselectorall-string)

[HtmlNode.cs:125](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L125)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

Parameters

**selector string required**

Returns

`IReadOnlyList<HtmlElement>`

`public void Remove()` [#](#method-remove)

[HtmlNode.cs:103](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L103)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public virtual string? ToString()` [#](#method-tostring)

Inherited from object

Returns

`string?`

## Properties

`public string LocalName { get; }` [#](#property-localname)

[HtmlElement.cs:21](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L21)

Element local name, preserving foreign-content case.

`public string NamespaceUri { get; }` [#](#property-namespaceuri)

[HtmlElement.cs:23](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L23)

Element namespace URI.

`public string Prefix { get; }` [#](#property-prefix)

[HtmlElement.cs:25](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L25)

Namespace prefix, or an empty string.

`public override string NodeName { get; }` [#](#property-nodename)

[HtmlElement.cs:27](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L27)

Node name for non-element nodes; elements expose their local name.

`public IReadOnlyList<HtmlAttribute> Attributes { get; }` [#](#property-attributes)

[HtmlElement.cs:29](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L29)

Ordered attributes.

`public string Id { get; }` [#](#property-id)

[HtmlElement.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L31)

Value of the empty-namespace id attribute, or an empty string.

`public string ClassName { get; }` [#](#property-classname)

[HtmlElement.cs:33](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L33)

Value of the empty-namespace class attribute, or an empty string.

`public IReadOnlyList<string> ClassList { get; }` [#](#property-classlist)

[HtmlElement.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L35)

Class tokens for inspection.

`public HtmlDocumentFragment? TemplateContent { get; internal set; }` [#](#property-templatecontent)

[HtmlElement.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L37)

Template contents, retained separately from normal child nodes.

`public HtmlFormControlState? FormState { get; set; }` [#](#property-formstate)

[HtmlElement.cs:42](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L42)

Optional immutable live form properties. Attributes and text retain their authored defaults.

## Inherited Properties

`public HtmlDocument Document { get; }` [#](#property-document)

[HtmlNode.cs:22](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L22)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public int NodeId { get; }` [#](#property-nodeid)

[HtmlNode.cs:24](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L24)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNodeKind Kind { get; }` [#](#property-kind)

[HtmlNode.cs:26](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L26)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? Parent { get; }` [#](#property-parent)

[HtmlNode.cs:28](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L28)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlElement? ParentElement { get; }` [#](#property-parentelement)

[HtmlNode.cs:31](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L31)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public IReadOnlyList<HtmlNode> ChildNodes { get; }` [#](#property-childnodes)

[HtmlNode.cs:33](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L33)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public IEnumerable<HtmlElement> Children { get; }` [#](#property-children)

[HtmlNode.cs:35](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L35)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? FirstChild { get; }` [#](#property-firstchild)

[HtmlNode.cs:37](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L37)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? NextSibling { get; }` [#](#property-nextsibling)

[HtmlNode.cs:39](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L39)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public HtmlNode? PreviousSibling { get; }` [#](#property-previoussibling)

[HtmlNode.cs:41](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L41)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public int? SourceIndex { get; internal set; }` [#](#property-sourceindex)

[HtmlNode.cs:43](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L43)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string TextContent { get; set; }` [#](#property-textcontent)

[HtmlNode.cs:49](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L49)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string OuterHtml { get; }` [#](#property-outerhtml)

[HtmlNode.cs:68](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L68)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

`public string InnerHtml { get; }` [#](#property-innerhtml)

[HtmlNode.cs:70](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlNode.cs#L70)

Inherited from [HtmlNode](/api/html-core/officeimo-html-dom-htmlnode/)

## Fields

`public const string HtmlNamespace` [#](#field-htmlnamespace)

[HtmlElement.cs:19](https://github.com/EvotecIT/OfficeIMO/blob/ba882f6b0d07acddd884b5e7d3086b0cfff0a05a/OfficeIMO.Html.Core/HtmlElement.cs#L19)

HTML namespace URI.

Value: `http://www.w3.org/1999/xhtml`

<!-- PowerForge markdown artifact sha256:91A56BD2514820843313F827CFC96A6E61E87D538528DC0C28CCAC3156D10E04 -->
